From 92f440d9de89d416491cbfeaba139b2e5ebbc021 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 29 Apr 2022 11:07:42 +0100 Subject: [PATCH] Consolidate deployment management into more maintained action (#8430) --- .github/workflows/element-build-and-test.yaml | 10 ++- .github/workflows/end-to-end-tests.yaml | 7 +- .github/workflows/netlify.yaml | 69 ++++++++----------- .github/workflows/static_analysis.yaml | 7 +- .github/workflows/tests.yml | 7 +- scripts/fetchdep.sh | 6 +- 6 files changed, 49 insertions(+), 57 deletions(-) diff --git a/.github/workflows/element-build-and-test.yaml b/.github/workflows/element-build-and-test.yaml index 1b736d2838..9b3d0f373a 100644 --- a/.github/workflows/element-build-and-test.yaml +++ b/.github/workflows/element-build-and-test.yaml @@ -8,13 +8,14 @@ on: branches: [ develop, master ] repository_dispatch: types: [ upstream-sdk-notify ] +env: + # These must be set for fetchdep.sh to get the right branch + REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} jobs: build: name: "Build Element-Web" runs-on: ubuntu-latest - env: - # This must be set for fetchdep.sh to get the right branch - PR_NUMBER: ${{github.event.number}} steps: - uses: actions/checkout@v2 @@ -90,9 +91,6 @@ jobs: app-tests: name: Element Web Integration Tests runs-on: ubuntu-latest - env: - # This must be set for fetchdep.sh to get the right branch - PR_NUMBER: ${{github.event.number}} steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index 1feaf266e3..6c663a0e01 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -9,12 +9,13 @@ on: branches: [ develop ] repository_dispatch: types: [ upstream-sdk-notify ] +env: + # These must be set for fetchdep.sh to get the right branch + REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} jobs: end-to-end: runs-on: ubuntu-latest - env: - # This must be set for fetchdep.sh to get the right branch - PR_NUMBER: ${{github.event.number}} container: vectorim/element-web-ci-e2etests-env:latest steps: - name: Checkout code diff --git a/.github/workflows/netlify.yaml b/.github/workflows/netlify.yaml index ac869121cd..260f8f130c 100644 --- a/.github/workflows/netlify.yaml +++ b/.github/workflows/netlify.yaml @@ -25,40 +25,40 @@ jobs: echo "PR number: $pr_number" echo "::set-output name=prnumber::$pr_number" - - name: Create Deployment ID - uses: altinukshini/deployment-action@v1.2.6 + - name: Create Deployment + uses: bobheadxi/deployments@v1 id: deployment with: - token: "${{ secrets.ELEMENT_BOT_TOKEN }}" - pr: true - pr_id: ${{ steps.readctx.outputs.prnumber }} - transient_environment: true - environment: Netlify - initial_status: in_progress + step: start + token: ${{ secrets.GITHUB_TOKEN }} + env: Netlify ref: ${{ github.event.workflow_run.head_sha }} + desc: | + Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. + Exercise caution. Use test accounts. - # There's a 'download artifact' action but it hasn't been updated for the + # There's a 'download artifact' action, but it hasn't been updated for the # workflow_run action (https://github.com/actions/download-artifact/issues/60) # so instead we get this mess: - name: 'Download artifact' uses: actions/github-script@v3.1.0 with: script: | - var artifacts = await github.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: ${{github.event.workflow_run.id }}, + const artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{ github.event.workflow_run.id }}, }); - var matchArtifact = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "previewbuild" + const matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "previewbuild" })[0]; - var download = await github.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', + const download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', }); - var fs = require('fs'); + const fs = require('fs'); fs.writeFileSync('${{github.workspace}}/previewbuild.zip', Buffer.from(download.data)); - name: Extract Artifacts @@ -79,25 +79,16 @@ jobs: NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} timeout-minutes: 1 - - name: Update deployment status (success) - if: success() - uses: altinukshini/deployment-status@v1.0.1 + - name: Update deployment status + uses: bobheadxi/deployments@v1 + if: always() with: - token: "${{ secrets.ELEMENT_BOT_TOKEN }}" - environment_url: ${{ steps.netlify.outputs.deploy-url }} - state: "success" + step: finish + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + env: ${{ steps.deployment.outputs.env }} deployment_id: ${{ steps.deployment.outputs.deployment_id }} - pr: true - pr_id: ${{ steps.readctx.outputs.prnumber }} - description: | + env_url: ${{ steps.netlify.outputs.deploy-url }} + desc: | Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts. - - name: Update deployment status (failure) - if: failure() - uses: altinukshini/deployment-status@v1.0.1 - with: - token: "${{ secrets.ELEMENT_BOT_TOKEN }}" - state: "failure" - deployment_id: ${{ steps.deployment.outputs.deployment_id }} - pr: true - pr_id: ${{ steps.readctx.outputs.prnumber }} diff --git a/.github/workflows/static_analysis.yaml b/.github/workflows/static_analysis.yaml index 8f568efc9c..63e939f7f9 100644 --- a/.github/workflows/static_analysis.yaml +++ b/.github/workflows/static_analysis.yaml @@ -5,13 +5,14 @@ on: branches: [ develop, master ] repository_dispatch: types: [ upstream-sdk-notify ] +env: + # These must be set for fetchdep.sh to get the right branch + REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} jobs: ts_lint: name: "Typescript Syntax Check" runs-on: ubuntu-latest - env: - # This must be set for fetchdep.sh to get the right branch - PR_NUMBER: ${{github.event.number}} steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dc11981b7c..f160e42844 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,13 +5,14 @@ on: branches: [ develop, master ] repository_dispatch: types: [ upstream-sdk-notify ] +env: + # These must be set for fetchdep.sh to get the right branch + REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} jobs: jest: name: Jest with Codecov runs-on: ubuntu-latest - env: - # This must be set for fetchdep.sh to get the right branch - PR_NUMBER: ${{github.event.number}} steps: - name: Checkout code uses: actions/checkout@v2 diff --git a/scripts/fetchdep.sh b/scripts/fetchdep.sh index 5d2e65c284..737e87844f 100755 --- a/scripts/fetchdep.sh +++ b/scripts/fetchdep.sh @@ -29,7 +29,7 @@ getPRInfo() { if [ -n "$number" ]; then echo "Getting info about a PR with number $number" - apiEndpoint="https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/" + apiEndpoint="https://api.github.com/repos/${REPOSITORY:-"matrix-org/matrix-react-sdk"}/pulls/" apiEndpoint+=$number head=$(curl $apiEndpoint | jq -r '.head.label') @@ -66,9 +66,9 @@ fi clone ${TRY_ORG} $defrepo ${TRY_BRANCH} # Try the target branch of the push or PR. -if [ -n $GITHUB_BASE_REF ]; then +if [ -n "$GITHUB_BASE_REF" ]; then clone $deforg $defrepo $GITHUB_BASE_REF -elif [ -n $BUILDKITE_PULL_REQUEST_BASE_BRANCH ]; then +elif [ -n "$BUILDKITE_PULL_REQUEST_BASE_BRANCH" ]; then clone $deforg $defrepo $BUILDKITE_PULL_REQUEST_BASE_BRANCH fi