From 52c7eec9d75c434edbd5112d2e735f99d2aaaa21 Mon Sep 17 00:00:00 2001 From: haphut Date: Wed, 29 Apr 2020 17:54:11 +0300 Subject: [PATCH 1/4] Ensure checking out the same commit everywhere --- .github/workflows/ci-cd.yaml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index c01d824f..fc2b281e 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -55,6 +55,15 @@ jobs: with: name: build path: ./build + # This is used to checkout the same SHA in later jobs + - name: Persist build commit SHA + run: | + mkdir -p ./build-commit-sha && echo "${GITHUB_SHA}" > ./build-commit-sha/sha + - name: Upload buld commit SHA + uses: actions/upload-artifact@v1 + with: + name: build-commit-sha + path: ./build-commit-sha publish-github-pages: name: Publish to GitHub Pages @@ -178,8 +187,22 @@ jobs: run: echo "::set-output name=url::$(cat ./netlify-draft-url/url)" # It is faster to install dependencies again than to download an artifact # containing everything. - - name: Check the repository out + # + # Also there can be a race condition where the wrong SHA is checked out if + # something else has been merged into master before this checkout but + # after the previous checkout within this same GitHub Actions run. Avoid + # the race condition by specifying the SHA. + - name: Download build commit SHA + uses: actions/download-artifact@v1 + with: + name: build-commit-sha + - name: Set build commit SHA to an output + id: build-commit-sha + run: echo "::set-output name=sha::$(cat ./build-commit-sha/sha)" + - name: Check the repository out at the same SHA as in build phase uses: actions/checkout@v2 + with: + ref: ${{ steps.build-commit-sha.outputs.sha }} - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: From ed92ed3acf0af9f3c910ff7286b78c2552ccfca0 Mon Sep 17 00:00:00 2001 From: haphut Date: Wed, 29 Apr 2020 17:54:56 +0300 Subject: [PATCH 2/4] Add a comment to CI/CD --- .github/workflows/ci-cd.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index fc2b281e..f5926ddb 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -149,6 +149,7 @@ jobs: environment_url: "${{ steps.publish-netlify.outputs.NETLIFY_URL }}", // auto_inactive: true, }) + # FIXME: Remove this step when deployment links show up on the PR page. - name: Post pull request comment with deployment link if: success() uses: actions/github-script@0.9.0 From acbc87b43dde7b854ce8c8c2f9e86a44e5344bc2 Mon Sep 17 00:00:00 2001 From: haphut Date: Sat, 2 May 2020 01:39:06 +0300 Subject: [PATCH 3/4] Use the official netlify/actions --- .github/workflows/ci-cd.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index f5926ddb..5521ade6 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -123,9 +123,7 @@ jobs: return(result.data.id); - name: Publish to Netlify id: publish-netlify - # FIXME: Once https://github.com/netlify/actions/pull/24 is merged, use - # the official one. - uses: Triloworld/actions/cli@3eff4d5cd9bf9f7ba528c1f1bbb94a37c3a3201d + uses: netlify/actions/cli@0b1104d9197d0ad6ac075a768fc7b76f86459a02 with: args: deploy --dir=./build --message=\"Triggered by event ${{ github.event_name }} for ref ${{ github.ref }} and commit ${{ github.sha }}\" env: @@ -267,9 +265,7 @@ jobs: return(result.data.id); - name: Publish to Netlify id: publish-netlify - # FIXME: Once https://github.com/netlify/actions/pull/24 is merged, use - # the official one. - uses: Triloworld/actions/cli@3eff4d5cd9bf9f7ba528c1f1bbb94a37c3a3201d + uses: netlify/actions/cli@0b1104d9197d0ad6ac075a768fc7b76f86459a02 with: args: deploy --dir=./build --prod --message=\"Triggered by event ${{ github.event_name }} for ref ${{ github.ref }} and commit ${{ github.sha }}\" env: From 6811a277e7efbce8f3795d2f461b4d577ad2d083 Mon Sep 17 00:00:00 2001 From: haphut Date: Wed, 29 Apr 2020 17:53:05 +0300 Subject: [PATCH 4/4] Use yarn cache explicitly --- .github/workflows/ci-cd.yaml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 5521ade6..3ecc1e12 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -34,8 +34,14 @@ jobs: key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - - name: Install dependencies - run: yarn --frozen-lockfile --non-interactive + - name: Install dependencies on a cache hit + if: steps.yarn-cache.outputs.cache-hit == 'true' + run: | + yarn --frozen-lockfile --non-interactive --offline + - name: Install dependencies on a cache miss + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: | + yarn --frozen-lockfile --non-interactive - name: Check that code passes type checking run: yarn type-check - name: Check that ESLint config is consistent with Prettier @@ -219,8 +225,14 @@ jobs: key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - - name: Install dependencies - run: yarn --frozen-lockfile --non-interactive + - name: Install dependencies on a cache hit + if: steps.yarn-cache.outputs.cache-hit == 'true' + run: | + yarn --frozen-lockfile --non-interactive --offline + - name: Install dependencies on a cache miss + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: | + yarn --frozen-lockfile --non-interactive - name: Install Playwright uses: microsoft/playwright-github-action@11413a1e4dfa5b193634b90340f5fadf22b81b27 - name: Run E2E tests using Netlify