From dbd12801f413317146cac5d593dae78ea298e7a6 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 20:10:30 +0300 Subject: [PATCH 01/17] ci: test-commit for PR deployment --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ebe379f..3d4c1467 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# React + TypeScript + Vite +# nimbus-gui This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. From 2f59a270c8ed1a5b53fc128101781489ee28915f Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 20:12:31 +0300 Subject: [PATCH 02/17] fix(ci): use `--token` for each command --- .github/workflows/ui-tests.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 5bbfbc4b..8f1f13ea 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -90,13 +90,13 @@ jobs: restore-keys: | ${{ runner.os }}-yarn-v3 - name: Log in to Vercel - run: yarn vercel login --token ${{ secrets.vercel_token }} + run: yarn vercel login - name: Pull Vercel configuration - run: yarn vercel pull --yes + run: yarn vercel pull --yes --token ${{ secrets.vercel_token }} - name: Build Vercel bundle run: yarn vercel build - name: Deploy to Vercel - run: yarn vercel deploy --prebuilt > _vercel-deployment-url + run: yarn vercel deploy --prebuilt --token ${{ secrets.vercel_token }} > _vercel-deployment-url - name: Comment on PR with deployment URL uses: actions/github-script@v4 with: From 7c918eb7eedf7233cb0003ffca1921b850cb5c3d Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 20:14:28 +0300 Subject: [PATCH 03/17] fix(ci): remove login --- .github/workflows/ui-tests.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 8f1f13ea..55e9383f 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -89,8 +89,6 @@ jobs: key: ${{ runner.os }}-yarn-v3-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn-v3 - - name: Log in to Vercel - run: yarn vercel login - name: Pull Vercel configuration run: yarn vercel pull --yes --token ${{ secrets.vercel_token }} - name: Build Vercel bundle From b7ba8927a20657989d7627f10f7fbb9e3f74fccd Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:10:01 +0300 Subject: [PATCH 04/17] fix(ci): use github script v6 & `rest` namespace --- .github/workflows/ui-tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 55e9383f..c056df68 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -96,13 +96,13 @@ jobs: - name: Deploy to Vercel run: yarn vercel deploy --prebuilt --token ${{ secrets.vercel_token }} > _vercel-deployment-url - name: Comment on PR with deployment URL - uses: actions/github-script@v4 + uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const fs = require('fs'); const deploymentUrl = fs.readFileSync('_vercel-deployment-url', 'utf8'); - github.issues.createComment({ + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, From d1576de028ccee103f02dc3f2c5c90acf4d1edc8 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:16:57 +0300 Subject: [PATCH 05/17] debug(ci): add console log of context To see if `issue` is available in the context. --- .github/workflows/ui-tests.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index c056df68..636a7cbd 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -79,6 +79,9 @@ jobs: - uses: actions/setup-node@v2 with: node-version: '18.x' + - uses: actions/github-script@v6 + with: + script: console.log(context) - name: Restore yarn dependencies uses: actions/cache@v2 id: yarn-cache From 3a85149d5512cb89885f609bd0cfcc37b6036c09 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:22:36 +0300 Subject: [PATCH 06/17] debug(ci): log `github.event` --- .github/workflows/ui-tests.yaml | 64 ++++++++++++--------------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 636a7cbd..b5b6bb77 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -22,7 +22,7 @@ jobs: if: steps.yarn-cache.outputs.cache-hit != 'true' run: yarn - build: + build-and-deploy: runs-on: ubuntu-latest needs: cache-dependencies steps: @@ -42,6 +42,28 @@ jobs: ${{ runner.os }}-yarn-v3 - name: Build run: yarn build + - uses: actions/github-script@v6 + with: + script: console.log(github.event) + - name: Pull Vercel configuration + run: yarn vercel pull --yes --token ${{ secrets.vercel_token }} + - name: Build Vercel bundle + run: yarn vercel build + - name: Deploy to Vercel + run: yarn vercel deploy --prebuilt --token ${{ secrets.vercel_token }} > _vercel-deployment-url + - name: Comment on PR with deployment URL + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + const deploymentUrl = fs.readFileSync('_vercel-deployment-url', 'utf8'); + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `Deployed to ${deploymentUrl}`, + }); interaction-and-and-accessibility: runs-on: ubuntu-latest @@ -71,43 +93,3 @@ jobs: "npx http-server storybook-static --port 6006 --silent" \ "npx wait-on tcp:127.0.0.1:6006 && yarn test-storybook" - deployment: - runs-on: ubuntu-latest - needs: cache-dependencies - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: '18.x' - - uses: actions/github-script@v6 - with: - script: console.log(context) - - name: Restore yarn dependencies - uses: actions/cache@v2 - id: yarn-cache - with: - path: | - ~/.cache/Cypress - node_modules - key: ${{ runner.os }}-yarn-v3-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn-v3 - - name: Pull Vercel configuration - run: yarn vercel pull --yes --token ${{ secrets.vercel_token }} - - name: Build Vercel bundle - run: yarn vercel build - - name: Deploy to Vercel - run: yarn vercel deploy --prebuilt --token ${{ secrets.vercel_token }} > _vercel-deployment-url - - name: Comment on PR with deployment URL - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const fs = require('fs'); - const deploymentUrl = fs.readFileSync('_vercel-deployment-url', 'utf8'); - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `Deployed to ${deploymentUrl}`, - }); From 0c4357abda364756c1b43e4ffcfbecbebc9c0d62 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:27:07 +0300 Subject: [PATCH 07/17] fix(ci): use step to get PR number via `gh` CLI --- .github/workflows/ui-tests.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index b5b6bb77..e92201df 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -2,6 +2,9 @@ name: 'UI tests' on: push +permissions: + pull_requests: read + jobs: cache-dependencies: runs-on: ubuntu-latest @@ -27,6 +30,11 @@ jobs: needs: cache-dependencies steps: - uses: actions/checkout@v2 + - name: Get PR number + id: pull_request + run: echo "::set-output name=number::$(gh pr view --json number -q .number || echo "")" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: actions/setup-node@v2 with: node-version: '18.x' @@ -59,7 +67,7 @@ jobs: const fs = require('fs'); const deploymentUrl = fs.readFileSync('_vercel-deployment-url', 'utf8'); await github.rest.issues.createComment({ - issue_number: context.issue.number, + issue_number: ${{ steps.pull_request.outputs.number }}, owner: context.repo.owner, repo: context.repo.repo, body: `Deployed to ${deploymentUrl}`, From c739109f7ce8e1ced843f0b997ba7b2b50c779e2 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:28:35 +0300 Subject: [PATCH 08/17] fix(ci): `pull_requests` -> `pull-requests` --- .github/workflows/ui-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index e92201df..77118ccf 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -3,7 +3,7 @@ name: 'UI tests' on: push permissions: - pull_requests: read + pull-requests: read jobs: cache-dependencies: From 646e06f553b9faec9aba7c217cb2f858e199f528 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:36:16 +0300 Subject: [PATCH 09/17] fix(ci): add write permissions for issues --- .github/workflows/ui-tests.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 77118ccf..3d36f531 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -4,6 +4,7 @@ on: push permissions: pull-requests: read + issues: write jobs: cache-dependencies: @@ -50,9 +51,6 @@ jobs: ${{ runner.os }}-yarn-v3 - name: Build run: yarn build - - uses: actions/github-script@v6 - with: - script: console.log(github.event) - name: Pull Vercel configuration run: yarn vercel pull --yes --token ${{ secrets.vercel_token }} - name: Build Vercel bundle From 9a1f19ecd10942d971d086ca96e1e3b206f00e0d Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:37:26 +0300 Subject: [PATCH 10/17] fix(ci): add rule for ui test deployment not running on `main` --- .github/workflows/ui-tests.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 3d36f531..4d4d0389 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -1,6 +1,9 @@ name: 'UI tests' -on: push +on: + push: + branches: + - !main permissions: pull-requests: read From d5b25c8243a13e0c637c856306dce1abb5dd113f Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:38:10 +0300 Subject: [PATCH 11/17] fix(ci): add quotes around `!main` --- .github/workflows/ui-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 4d4d0389..cc6b8398 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -3,7 +3,7 @@ name: 'UI tests' on: push: branches: - - !main + - '!main' permissions: pull-requests: read From a0dba91951cabf73bfe023dc0c3bb8b7eb979474 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:38:42 +0300 Subject: [PATCH 12/17] fix(ci): add wildcard branch name to trigger branches --- .github/workflows/ui-tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index cc6b8398..9edbe5bb 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -3,6 +3,7 @@ name: 'UI tests' on: push: branches: + - '*' - '!main' permissions: From 31197c1f71c3df7442fa193912b37525b5510ac9 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:46:16 +0300 Subject: [PATCH 13/17] debug(ci): set permissions to PRs write --- .github/workflows/ui-tests.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 9edbe5bb..31602f7d 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -7,8 +7,7 @@ on: - '!main' permissions: - pull-requests: read - issues: write + pull-requests: write jobs: cache-dependencies: From 1e27bc64cf5810f45c81145d5db2829a88b75566 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:53:03 +0300 Subject: [PATCH 14/17] fix(ci): add deployment so it shows up as deployed in PR --- .github/workflows/ui-tests.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 31602f7d..894a903d 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -73,6 +73,26 @@ jobs: repo: context.repo.repo, body: `Deployed to ${deploymentUrl}`, }); + - name: Add deployment to PR + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + const deploymentUrl = fs.readFileSync('_vercel-deployment-url', 'utf8'); + await github.rest.repos.createDeployment({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: context.sha, + environment: 'preview', + transient_environment: true, + required_contexts: [], + auto_merge: false, + production_environment: false, + payload: JSON.stringify({ + deploymentUrl, + }), + }); interaction-and-and-accessibility: runs-on: ubuntu-latest From 662dbf3d0fd746cad451feba242390e301f4d8a7 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 21:57:32 +0300 Subject: [PATCH 15/17] fix(ci): add deployments write permission --- .github/workflows/ui-tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 894a903d..14a268ae 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -8,6 +8,7 @@ on: permissions: pull-requests: write + deployments: write jobs: cache-dependencies: From 6c8aa634e7b6ba0a80749b2e10e7f495b72c01dd Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 22:09:30 +0300 Subject: [PATCH 16/17] debug(ci): add deployment status step in workflow --- .github/workflows/ui-tests.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 14a268ae..7439115a 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -94,6 +94,24 @@ jobs: deploymentUrl, }), }); + - name: Add deployment status to PR + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + const deploymentUrl = fs.readFileSync('_vercel-deployment-url', 'utf8'); + await github.rest.repos.createDeploymentStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + deployment_id: context.payload.deployment.id, + state: 'success', + environment_url: deploymentUrl, + log_url: deploymentUrl, + description: 'Deployed to Vercel', + environment: 'preview', + auto_inactive: true, + }); interaction-and-and-accessibility: runs-on: ubuntu-latest From 5c847467e5da52d9c89c52137b7efda66ce1c67d Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Wed, 23 Aug 2023 22:15:42 +0300 Subject: [PATCH 17/17] fix(ci): pull out deployment ID from API response --- .github/workflows/ui-tests.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ui-tests.yaml b/.github/workflows/ui-tests.yaml index 7439115a..4a5817b6 100644 --- a/.github/workflows/ui-tests.yaml +++ b/.github/workflows/ui-tests.yaml @@ -76,12 +76,13 @@ jobs: }); - name: Add deployment to PR uses: actions/github-script@v6 + id: deployment with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const fs = require('fs'); const deploymentUrl = fs.readFileSync('_vercel-deployment-url', 'utf8'); - await github.rest.repos.createDeployment({ + const deployment = await github.rest.repos.createDeployment({ owner: context.repo.owner, repo: context.repo.repo, ref: context.sha, @@ -94,6 +95,7 @@ jobs: deploymentUrl, }), }); + console.log("::set-output name=deployment_id::" + deployment.data.id); - name: Add deployment status to PR uses: actions/github-script@v6 with: @@ -104,7 +106,7 @@ jobs: await github.rest.repos.createDeploymentStatus({ owner: context.repo.owner, repo: context.repo.repo, - deployment_id: context.payload.deployment.id, + deployment_id: ${{ steps.deployment.outputs.deployment_id }}, state: 'success', environment_url: deploymentUrl, log_url: deploymentUrl,