From fa09bd7e2c261a4fbb6fc3c5bd322e31c0a5a30f Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Tue, 5 Sep 2023 10:11:32 +0200 Subject: [PATCH 01/14] feat: add ignore-build --- ignore_build.ts | 30 ++++++++++++++++++++++++++++++ netlify.toml | 2 ++ 2 files changed, 32 insertions(+) create mode 100644 ignore_build.ts create mode 100644 netlify.toml diff --git a/ignore_build.ts b/ignore_build.ts new file mode 100644 index 000000000..469ceab45 --- /dev/null +++ b/ignore_build.ts @@ -0,0 +1,30 @@ +// 1 -> continue build +// 0 -> stop build + +console.log(process.env); +if (process.env.CONTEXT !== 'branch.preview') { + process.exitCode = 1; +} else { + const pull_number = process.env.REVIEW_ID; + const owner = 'satellytes'; + const repo = 'satellytes.com'; + const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}`; + const token = process.env.GITHUB_ACCESS_TOKEN; + const params = { + headers: { + Accept: 'application/vnd.github+json', + Authorization: `Bearer ${token}`, + 'X-GitHub-Api-Version': '2022-11-28', + }, + method: 'GET', + }; + fetch(url, params) + .then((data) => data.json()) + .then((res) => { + console.log(res); + const shouldBuild = res.labels.find( + (label) => label.name === 'deploy-me', + ); + return shouldBuild ? 1 : 0; + }); +} diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 000000000..99bfbc322 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,2 @@ +[build] + ignore = "node ignore_build.ts" \ No newline at end of file From a9d1e6d8bf19c55afd4eb493ad9f2a4e595f0566 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Tue, 5 Sep 2023 10:26:34 +0200 Subject: [PATCH 02/14] fix: correct context name --- ignore_build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignore_build.ts b/ignore_build.ts index 469ceab45..2b49d2712 100644 --- a/ignore_build.ts +++ b/ignore_build.ts @@ -2,7 +2,7 @@ // 0 -> stop build console.log(process.env); -if (process.env.CONTEXT !== 'branch.preview') { +if (process.env.CONTEXT !== 'deploy-preview') { process.exitCode = 1; } else { const pull_number = process.env.REVIEW_ID; From 582c285b82653d3c7a9b1c59e6776082049eb7b1 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Tue, 5 Sep 2023 11:55:57 +0200 Subject: [PATCH 03/14] feat: netlify github workflow --- .github/workflows/netlify-build.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/netlify-build.yml diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml new file mode 100644 index 000000000..88de23707 --- /dev/null +++ b/.github/workflows/netlify-build.yml @@ -0,0 +1,16 @@ +name: Netlify Build + +on: + pull_request: + types: [ labeled, opened, synchronize, reopened ] + +jobs: + deploy: + if: github.event.label.name == 'deploy-me' + runs-on: ubuntu-latest + env: + NETLIFY_BUILD_WEBHOOK_URL: ${{ secrets.NETLIFY_BUILD_WEBHOOK_URL }} + PR_TITLE: ${{ github.event.pull_request.title }} + steps: + - name: Trigger build and deployment + run: curl -X POST -d {} '$NETLIFY_BUILD_WEBHOOK_URL?trigger_branch=$PR_TITLE' \ No newline at end of file From b5e3b4152d67892cbcff13c0c27005d8d003a87b Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Tue, 5 Sep 2023 11:59:06 +0200 Subject: [PATCH 04/14] feat: delete unnecessary files --- ignore_build.ts | 30 ------------------------------ netlify.toml | 2 -- 2 files changed, 32 deletions(-) delete mode 100644 ignore_build.ts delete mode 100644 netlify.toml diff --git a/ignore_build.ts b/ignore_build.ts deleted file mode 100644 index 2b49d2712..000000000 --- a/ignore_build.ts +++ /dev/null @@ -1,30 +0,0 @@ -// 1 -> continue build -// 0 -> stop build - -console.log(process.env); -if (process.env.CONTEXT !== 'deploy-preview') { - process.exitCode = 1; -} else { - const pull_number = process.env.REVIEW_ID; - const owner = 'satellytes'; - const repo = 'satellytes.com'; - const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}`; - const token = process.env.GITHUB_ACCESS_TOKEN; - const params = { - headers: { - Accept: 'application/vnd.github+json', - Authorization: `Bearer ${token}`, - 'X-GitHub-Api-Version': '2022-11-28', - }, - method: 'GET', - }; - fetch(url, params) - .then((data) => data.json()) - .then((res) => { - console.log(res); - const shouldBuild = res.labels.find( - (label) => label.name === 'deploy-me', - ); - return shouldBuild ? 1 : 0; - }); -} diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index 99bfbc322..000000000 --- a/netlify.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] - ignore = "node ignore_build.ts" \ No newline at end of file From bca835259c9df41c29f7353932c15ec0ff9fa1b5 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Thu, 7 Sep 2023 11:09:00 +0200 Subject: [PATCH 05/14] feat: add github action --- .github/workflows/netlify-build.yml | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index 88de23707..27a26e987 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -1,16 +1,28 @@ -name: Netlify Build +name: Build and Deploy to Netlify on: pull_request: types: [ labeled, opened, synchronize, reopened ] jobs: - deploy: - if: github.event.label.name == 'deploy-me' + build: runs-on: ubuntu-latest - env: - NETLIFY_BUILD_WEBHOOK_URL: ${{ secrets.NETLIFY_BUILD_WEBHOOK_URL }} - PR_TITLE: ${{ github.event.pull_request.title }} + if: contains( github.event.pull_request.labels.*.name, 'deploy-me') steps: - - name: Trigger build and deployment - run: curl -X POST -d {} '$NETLIFY_BUILD_WEBHOOK_URL?trigger_branch=$PR_TITLE' \ No newline at end of file + - uses: actions/checkout@v3 + - name: Deploy to Netlify + uses: nwtgck/actions-netlify@v2.0 + with: + publish-dir: './dist' + production-branch: main + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: "Deploy from GitHub Actions" + enable-pull-request-comment: true + enable-commit-comment: true + overwrites-pull-request-comment: true + functions-dir: './netlify/functions' + enable-github-deployment: false + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + timeout-minutes: 1 From 1d1849dc3ef4b5e3cc9ac526730b193040423a2a Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Thu, 7 Sep 2023 11:12:07 +0200 Subject: [PATCH 06/14] fix: remove invalid input --- .github/workflows/netlify-build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index 27a26e987..838dbbcfa 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -20,7 +20,6 @@ jobs: enable-pull-request-comment: true enable-commit-comment: true overwrites-pull-request-comment: true - functions-dir: './netlify/functions' enable-github-deployment: false env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} From 389f5a2cdbef278d56b19f08e089625324c5ea24 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Thu, 7 Sep 2023 11:36:12 +0200 Subject: [PATCH 07/14] feat: build in netlify workflow --- .github/workflows/netlify-build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index 838dbbcfa..a23d1bdb1 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -10,10 +10,14 @@ jobs: if: contains( github.event.pull_request.labels.*.name, 'deploy-me') steps: - uses: actions/checkout@v3 + - name: Install and Build + run: | + yarn install + yarn run build - name: Deploy to Netlify uses: nwtgck/actions-netlify@v2.0 with: - publish-dir: './dist' + publish-dir: './public' production-branch: main github-token: ${{ secrets.GITHUB_TOKEN }} deploy-message: "Deploy from GitHub Actions" From 6bd47a66c5e5885b533df9a22879e18179f3c3ff Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Thu, 7 Sep 2023 13:25:04 +0200 Subject: [PATCH 08/14] feat: build in netlify workflow --- .github/workflows/netlify-build.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index a23d1bdb1..b09a243a9 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -9,11 +9,20 @@ jobs: runs-on: ubuntu-latest if: contains( github.event.pull_request.labels.*.name, 'deploy-me') steps: - - uses: actions/checkout@v3 - - name: Install and Build - run: | - yarn install - yarn run build + - name: Checkout + uses: actions/checkout@v3 + - name: Setup + uses: actions/setup-node@v3 + with: + node-version: '18' + cache: 'yarn' + - name: Install + run: yarn install --frozen-lockfile + - name: Build + run: yarn build + env: + CONTENTFUL_SPACE_ID: ${{ secrets.CONTENTFUL_SPACE_ID }} + CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CONTENTFUL_ACCESS_TOKEN }} - name: Deploy to Netlify uses: nwtgck/actions-netlify@v2.0 with: From df845518d7183566f894385ea47002157e89bb45 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Thu, 7 Sep 2023 13:31:59 +0200 Subject: [PATCH 09/14] fix: correct file error --- .github/workflows/netlify-build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index b09a243a9..dd30217d2 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -13,11 +13,11 @@ jobs: uses: actions/checkout@v3 - name: Setup uses: actions/setup-node@v3 - with: - node-version: '18' - cache: 'yarn' + with: + node-version: '18' + cache: 'yarn' - name: Install - run: yarn install --frozen-lockfile + run: yarn install --frozen-lockfile - name: Build run: yarn build env: From 52089c6eb42a79e70c62f7fd32195939a3f76ce7 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Thu, 7 Sep 2023 15:24:51 +0200 Subject: [PATCH 10/14] fix: workflow name --- .github/workflows/netlify-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index dd30217d2..de54f03b1 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -28,7 +28,7 @@ jobs: with: publish-dir: './public' production-branch: main - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.ACCESS_TOKEN_GITHUB }} deploy-message: "Deploy from GitHub Actions" enable-pull-request-comment: true enable-commit-comment: true From a2877a5a86dc2e5ca90f1445b8897aacc0142e0d Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Thu, 7 Sep 2023 15:36:11 +0200 Subject: [PATCH 11/14] fix: workflow name --- .github/workflows/netlify-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index de54f03b1..8aad9a9b6 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -28,7 +28,7 @@ jobs: with: publish-dir: './public' production-branch: main - github-token: ${{ secrets.ACCESS_TOKEN_GITHUB }} + github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} deploy-message: "Deploy from GitHub Actions" enable-pull-request-comment: true enable-commit-comment: true From 9b1fb90af046c209f9ba5c82a4b8568584e860e4 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Thu, 7 Sep 2023 16:03:55 +0200 Subject: [PATCH 12/14] fix: replace preview alias --- .github/workflows/netlify-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index 8aad9a9b6..6ea544f6a 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -34,6 +34,7 @@ jobs: enable-commit-comment: true overwrites-pull-request-comment: true enable-github-deployment: false + alias: deploy-preview-${{ github.event.number }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} From 50c93633d6d60de35e50776452fd7dc497160c05 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Mon, 11 Sep 2023 08:52:50 +0200 Subject: [PATCH 13/14] feat: replace deploy message --- .github/workflows/netlify-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index 6ea544f6a..4b8c628a4 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -29,7 +29,7 @@ jobs: publish-dir: './public' production-branch: main github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - deploy-message: "Deploy from GitHub Actions" + deploy-message: ${{ github.event.pull_request.title }} enable-pull-request-comment: true enable-commit-comment: true overwrites-pull-request-comment: true From 30036ba0a9f070a20af5a2f64cfb2839d161d0d8 Mon Sep 17 00:00:00 2001 From: Wiebke Freitag Date: Mon, 11 Sep 2023 11:36:34 +0200 Subject: [PATCH 14/14] feat: show commit message --- .github/workflows/netlify-build.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/netlify-build.yml b/.github/workflows/netlify-build.yml index 4b8c628a4..2905e0df6 100644 --- a/.github/workflows/netlify-build.yml +++ b/.github/workflows/netlify-build.yml @@ -11,6 +11,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Get Head Commit Message + id: get_head_commit_message + run: echo "HEAD_COMMIT_MESSAGE=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT" - name: Setup uses: actions/setup-node@v3 with: @@ -29,7 +34,7 @@ jobs: publish-dir: './public' production-branch: main github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - deploy-message: ${{ github.event.pull_request.title }} + deploy-message: '#${{ github.event.number }} ${{ github.event.pull_request.title }}: ${{ steps.get_head_commit_message.outputs.HEAD_COMMIT_MESSAGE }}' enable-pull-request-comment: true enable-commit-comment: true overwrites-pull-request-comment: true