From f3881a60511db355db9ba9ed5848426c82b6acd1 Mon Sep 17 00:00:00 2001 From: Shiying Chen Date: Thu, 22 Feb 2024 13:25:00 +0800 Subject: [PATCH] {Automation} Add CI tests (#136) --- .github/workflows/build-release.yml | 6 +- .github/workflows/ci-workflow.yml | 25 ++--- .github/workflows/integration-test.yml | 91 +++++++++++++++++++ .github/workflows/pr-test.yml | 121 +++++++++++++++++++++++++ 4 files changed, 223 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/integration-test.yml create mode 100644 .github/workflows/pr-test.yml diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 13f95360..d96460ab 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -14,12 +14,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Code - uses: actions/checkout@master + uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: - node-version: "16.x" + node-version: "20.x" - run: sudo npm i -g @vercel/ncc diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml index 0a9e5326..c69f644b 100644 --- a/.github/workflows/ci-workflow.yml +++ b/.github/workflows/ci-workflow.yml @@ -1,8 +1,6 @@ name: ci-workflow on: push: - schedule: - - cron: '0 */3 * * *' workflow_dispatch: jobs: @@ -10,17 +8,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out source code - uses: actions/checkout@v1 + uses: actions/checkout@v4 + - uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} + - name: Setup Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: - node-version: "16.x" + node-version: "20.x" + - run: npm install --production - - run: sudo npm i -g ts-node + - run: npm i -g ts-node - run: npm install typescript - name: Azure CLI Version test @@ -46,14 +47,4 @@ jobs: INPUT_AZCLIVERSION: 2.0.72 INPUT_INLINESCRIPT: " " EXPECTED_TO: fail - run: ts-node test/main.test.ts - - - name: Post to slack on failure - if: failure() - uses: 8398a7/action-slack@v3.9.1 - with: - status: ${{ job.status }} - fields: repo,message,author,action,ref,workflow - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - + run: ts-node test/main.test.ts \ No newline at end of file diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 00000000..5cb4d6e1 --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,91 @@ +name: integration-test +on: + workflow_dispatch: + schedule: + - cron: '0 */3 * * *' + +jobs: + basic_test: + runs-on: ubuntu-latest + steps: + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Specific test - Postive + uses: azure/cli@master + with: + azcliversion: 2.30.0 + inlineScript: | + az --version + az account show --output none + + - name: Latest version test - Postive + uses: azure/cli@master + with: + azcliversion: latest + inlineScript: | + az --version + az account show --output none + + - name: Default version test - Postive + uses: azure/cli@master + with: + inlineScript: | + az --version + az account show --output none + + - name: Invalid Version test - Negative + id: test1 + continue-on-error: true + uses: azure/cli@master + with: + azcliversion: 0 + inlineScript: | + az --version + + - name: Check Last step failed + if: steps.test1.outcome == 'success' + uses: actions/github-script@v3 + with: + script: | + core.setFailed('Last action should fail but not. Please check it.') + + - name: Invalid Script test - Negative + id: test2 + continue-on-error: true + uses: azure/cli@master + with: + azcliversion: latest + inlineScript: " " + + - name: Check Last step failed + if: steps.test2.outcome == 'success' + uses: actions/github-script@v3 + with: + script: | + core.setFailed('Last action should fail but not. Please check it.') + + os_test: + environment: Automation Test + runs-on: windows-latest + steps: + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Invalid OS - Negative + id: test3 + continue-on-error: true + uses: azure/cli@master + with: + azcliversion: latest + inlineScript: | + az --version + + - name: Check Last step failed + if: steps.test3.outcome == 'success' + uses: actions/github-script@v3 + with: + script: | + core.setFailed('Last action should fail but not. Please check it.') \ No newline at end of file diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml new file mode 100644 index 00000000..add39f8e --- /dev/null +++ b/.github/workflows/pr-test.yml @@ -0,0 +1,121 @@ +name: pr-test +on: + pull_request_target: + branches: + - master + - releases/* + push: + workflow_dispatch: + +jobs: + basic_test: + environment: Automation Test + runs-on: ubuntu-latest + steps: + - name: Check out source code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" + + - name: Install dependencies + run: | + npm i -g @vercel/ncc + npm install + + - name: Compile files + run: | + ncc build -C -m src/entrypoint.ts + + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Test - Postive + uses: ./ + with: + azcliversion: 2.30.0 + inlineScript: | + az --version + az account show --output none + + - name: Default version test - Postive + uses: ./ + with: + inlineScript: | + az --version + az account show --output none + + - name: Invalid Version test - Negative + id: test1 + continue-on-error: true + uses: ./ + with: + azcliversion: 0 + inlineScript: | + az --version + + - name: Check Last step failed + if: steps.test1.outcome == 'success' + uses: actions/github-script@v3 + with: + script: | + core.setFailed('Last action should fail but not. Please check it.') + + - name: Invalid Script test - Negative + id: test2 + continue-on-error: true + uses: ./ + with: + azcliversion: latest + inlineScript: " " + + - name: Check Last step failed + if: steps.test2.outcome == 'success' + uses: actions/github-script@v3 + with: + script: | + core.setFailed('Last action should fail but not. Please check it.') + + os_test: + environment: Automation Test + runs-on: windows-latest + steps: + - name: Check out source code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" + + - name: Install dependencies + run: | + npm i -g @vercel/ncc + npm install + + - name: Compile files + run: | + ncc build -C -m src/entrypoint.ts + + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Invalid OS - Negative + id: test3 + continue-on-error: true + uses: ./ + with: + azcliversion: latest + inlineScript: | + az --version + + - name: Check Last step failed + if: steps.test3.outcome == 'success' + uses: actions/github-script@v3 + with: + script: | + core.setFailed('Last action should fail but not. Please check it.')