Backend Test #670
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Backend Test | |
| permissions: | |
| contents: read | |
| checks: write | |
| statuses: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| deployment: | |
| required: true | |
| type: choice | |
| default: "govtool.cardanoapi.io/api" | |
| options: | |
| - "sanchogov.tools/api" | |
| - "staging.govtool.byron.network/api" | |
| - "govtool.cardanoapi.io/api" | |
| - "be.preview.gov.tools" | |
| - "z6b8d2f7a-zca4a4c45-gtw.z937eb260.rustrocks.fr" | |
| - "z78acf3c2-z5575152b-gtw.z937eb260.rustrocks.fr" | |
| - "be.gov.tools" | |
| network: | |
| required: true | |
| type: choice | |
| default: "preview" | |
| options: | |
| - "sanchonet" | |
| - "preview" | |
| - "mainnet" | |
| - "preprod" | |
| workflow_run: | |
| workflows: ["Build and deploy GovTool test stack"] | |
| types: [completed] | |
| branches: | |
| - test | |
| - infra/test-chores | |
| schedule: | |
| - cron: "0 0 * * *" # 12AM UTC | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| backend-tests: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' || github.event.schedule }} | |
| outputs: | |
| start_time: ${{ steps.set-pending-status.outputs.timestamp }} | |
| status: ${{ steps.run-tests.outcome }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.COMMIT_SHA }} | |
| - name: Set pending commit status | |
| id: set-pending-status | |
| if: ${{ !github.event.schedule }} | |
| run: | | |
| echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT | |
| curl -X POST -H "Authorization: Bearer ${{ github.token }}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.COMMIT_SHA }} \ | |
| -d "{\"state\": \"pending\", \"context\": \"Backend Tests : ${{env.BASE_URL}}\", \"target_url\": \"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.11.4 | |
| cache: "pip" | |
| - name: Run Backend Test | |
| working-directory: tests/govtool-backend | |
| id: run-tests | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| if [[ "${{ env.NETWORK }}" == "preprod" ]]; then | |
| export FAUCET_API_KEY="${{ secrets.FAUCET_API_KEY_PREPROD }}" | |
| elif [[ "${{ env.NETWORK }}" == "sanchonet" ]]; then | |
| export FAUCET_API_KEY="${{ secrets.FAUCET_API_KEY_SANCHONET }}" | |
| else | |
| export FAUCET_API_KEY="${{ secrets.FAUCET_API_KEY_PREVIEW }}" | |
| fi | |
| python ./setup.py | |
| python -m pytest --alluredir allure-results | |
| - name: Upload report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: allure-results | |
| path: tests/govtool-backend/allure-results | |
| env: | |
| NETWORK: ${{ inputs.network || vars.NETWORK }} | |
| KUBER_API_KEY: ${{ secrets.KUBER_API_KEY }} | |
| publish-report: | |
| runs-on: ubuntu-latest | |
| if: always() && needs.backend-tests.result != 'skipped' | |
| needs: backend-tests | |
| outputs: | |
| report_number: ${{ steps.report-details.outputs.report_number }} | |
| group_name: ${{ steps.set-deployment-url.outputs.group_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: allure-results | |
| path: allure-results | |
| - name: Get Allure history | |
| uses: actions/checkout@v4 | |
| continue-on-error: true | |
| with: | |
| ref: gh-pages | |
| path: gh-pages | |
| repository: ${{vars.GH_PAGES}} | |
| ssh-key: ${{ secrets.DEPLOY_KEY }} | |
| - name: Set Deployment Environment | |
| id: set-deployment-url | |
| run: | | |
| chmod +x .github/scripts/set_deployment_environment.sh | |
| .github/scripts/set_deployment_environment.sh | |
| - name: Remove oldest report to save space | |
| if: ${{success()}} | |
| run: | | |
| chmod +x .github/scripts/remove_oldest_report.sh | |
| .github/scripts/remove_oldest_report.sh | |
| - name: Generate report details | |
| id: report-details | |
| run: | | |
| chmod +x .github/scripts/generate_report_details.sh | |
| .github/scripts/generate_report_details.sh | |
| - name: Build report | |
| uses: simple-elf/allure-report-action@master | |
| id: allure-report | |
| with: | |
| allure_results: allure-results | |
| gh_pages: gh-pages/${{steps.set-deployment-url.outputs.group_name}}/${{env.REPORT_NAME}} | |
| allure_report: allure-report | |
| allure_history: allure-history | |
| keep_reports: 2000 | |
| report_url: ${{steps.report-details.outputs.report_url}} | |
| github_run_num: ${{steps.report-details.outputs.report_number}} | |
| - name: Generate Latest Report | |
| run: | | |
| chmod +x .github/scripts/generate_latest_report_redirect.sh | |
| .github/scripts/generate_latest_report_redirect.sh ${{steps.report-details.outputs.report_number}} | |
| - name: Deploy report to Github Pages | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| ssh-key: ${{ secrets.DEPLOY_KEY }} | |
| repository-name: ${{vars.GH_PAGES}} | |
| branch: gh-pages | |
| folder: build | |
| target-folder: ${{steps.set-deployment-url.outputs.group_name}}/${{ env.REPORT_NAME }} | |
| publish-status: | |
| runs-on: ubuntu-latest | |
| if: always() && needs.backend-tests.result != 'skipped' | |
| needs: [backend-tests, publish-report] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: allure-results | |
| path: allure-results | |
| - name: Set Commit Status | |
| if: always() && !github.event.schedule | |
| run: | | |
| chmod +x .github/scripts/set_commit_status.sh | |
| .github/scripts/set_commit_status.sh | |
| env: | |
| START_TIME: ${{ needs.backend-tests.outputs.start_time }} | |
| TEST_STATUS: ${{ needs.backend-tests.outputs.status }} | |
| REPORT_NUMBER: ${{ needs.publish-report.outputs.report_number }} | |
| GITHUB_TOKEN: ${{ github.token }} | |
| GROUP_NAME: ${{ needs.publish-report.outputs.group_name }} | |
| env: | |
| BASE_URL: https://${{github.event.schedule && 'be.preview.gov.tools' || inputs.deployment || 'govtool.cardanoapi.io/api' }} | |
| DEPLOYMENT: ${{ github.event.schedule && 'be.preview.gov.tools' || inputs.deployment || 'govtool.cardanoapi.io/api'}} | |
| REPORT_NAME: ${{ github.event.schedule && 'nightly-'}}govtool-backend | |
| GH_PAGES: ${{vars.GH_PAGES}} | |
| COMMIT_SHA: ${{ github.event.workflow_run.head_sha || github.sha }} |