From 95521e12ef6b8534e5fdf610967e881d5481328d Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Tue, 18 Jun 2024 13:07:51 +0900 Subject: [PATCH 1/2] =?UTF-8?q?ci:=20=E3=83=87=E3=83=97=E3=83=AD=E3=82=A4?= =?UTF-8?q?=E9=96=A2=E9=80=A3=E3=81=AE=E3=83=AF=E3=83=BC=E3=82=AF=E3=83=95?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd.yml | 12 +++ .github/workflows/preview.yml | 26 +++++++ .github/workflows/production.yml | 24 ++++++ .github/workflows/wc-changed.yml | 10 +++ .../workflows/wc-deploy-cloudflare-pages.yml | 76 +++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 .github/workflows/preview.yml create mode 100644 .github/workflows/production.yml create mode 100644 .github/workflows/wc-deploy-cloudflare-pages.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 6929e17..ea4a22f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -16,3 +16,15 @@ jobs: gh-app-id: ${{ vars.BOT_APP_ID }} secrets: gh-app-private-key: ${{ secrets.BOT_PRIVATE_KEY }} + + deploy: + uses: ./.github/workflows/wc-deploy-cloudflare-pages.yml + with: + project-name: 'asis-quest-staging' + branch: 'main' + gh-app-id: ${{ vars.BOT_APP_ID }} + pr-comment-enabled: false + secrets: + cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }} + gh-app-private-key: ${{ secrets.BOT_PRIVATE_KEY }} diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000..c58c4e0 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,26 @@ +name: "Preview" + +on: + pull_request: + +concurrency: + group: preview-${{ github.ref }} + cancel-in-progress: true + +jobs: + changed: + uses: ./.github/workflows/wc-changed.yml + + preview: + uses: ./.github/workflows/wc-deploy-cloudflare-pages.yml + needs: changed + if: needs.changed.outputs.website == 'true' + with: + project-name: 'asis-quest' + branch: 'preview' + gh-app-id: ${{ vars.BOT_APP_ID }} + pr-comment-enabled: true + secrets: + cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }} + gh-app-private-key: ${{ secrets.BOT_PRIVATE_KEY }} diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml new file mode 100644 index 0000000..720f3d5 --- /dev/null +++ b/.github/workflows/production.yml @@ -0,0 +1,24 @@ +name: 'Production' + +on: + push: + tags: + - "v*" + workflow_dispatch: + +concurrency: + group: production-${{ github.ref }} + cancel-in-progress: true + +jobs: + deploy: + uses: ./.github/workflows/wc-deploy-cloudflare-pages.yml + with: + project-name: 'asis-quest' + branch: 'main' + gh-app-id: ${{ vars.BOT_APP_ID }} + pr-comment-enabled: false + secrets: + cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }} + gh-app-private-key: ${{ secrets.BOT_PRIVATE_KEY }} diff --git a/.github/workflows/wc-changed.yml b/.github/workflows/wc-changed.yml index 69c02cc..9682ad3 100644 --- a/.github/workflows/wc-changed.yml +++ b/.github/workflows/wc-changed.yml @@ -5,6 +5,8 @@ on: outputs: actions: value: ${{ jobs.changed.outputs.actions }} + website: + value: ${{ jobs.changed.outputs.website }} permissions: contents: read @@ -15,6 +17,7 @@ jobs: runs-on: ubuntu-22.04 outputs: actions: ${{ steps.changes.outputs.actions }} + website: ${{ steps.changes.outputs.website }} steps: # https://github.com/marketplace/actions/checkout - name: Checkout @@ -28,3 +31,10 @@ jobs: filters: | actions: - '.github/workflows/*.yml' + website: + - 'public/**/*' + - 'src/**/*' + - '.tool-versions' + - 'astro.config.mjs' + - 'package.json' + - 'tsconfig.json' diff --git a/.github/workflows/wc-deploy-cloudflare-pages.yml b/.github/workflows/wc-deploy-cloudflare-pages.yml new file mode 100644 index 0000000..281b2c1 --- /dev/null +++ b/.github/workflows/wc-deploy-cloudflare-pages.yml @@ -0,0 +1,76 @@ +name: "Deploy Cloudflare Pages" + +on: + workflow_call: + inputs: + project-name: + required: true + type: string + branch: + required: true + type: string + gh-app-id: + required: true + type: string + pr-comment-enabled: + required: true + type: boolean + secrets: + gh-app-private-key: + required: true + cloudflare-account-id: + required: true + cloudflare-api-token: + required: true + +permissions: + contents: read + deployments: write + pull-requests: write + +jobs: + deploy-cloudflare-pages: + runs-on: ubuntu-22.04 + steps: + # https://github.com/marketplace/actions/checkout + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + # https://github.com/marketplace/actions/mise-action + - name: mise action + uses: jdx/mise-action@d6e32c1796099e0f1f3ac741c220a8b7eae9e5dd # v2.0.6 + + - name: Install deps + run: bun install --frozen-lockfile + + - name: Build + run: bun run build + + # https://github.com/marketplace/actions/create-github-app-token + - name: Create GitHub App Token + uses: actions/create-github-app-token@c8f55efbd427e7465d6da1106e7979bc8aaee856 # v1.10.1 + id: app-token + with: + app-id: ${{ inputs.gh-app-id }} + private-key: ${{ secrets.gh-app-private-key }} + + # https://github.com/marketplace/actions/cloudflare-pages-github-action + - name: Publish to Cloudflare Pages + uses: cloudflare/pages-action@f0a1cd58cd66095dee69bfa18fa5efd1dde93bca # v1.5.0 + id: cloudflare-pages + with: + apiToken: ${{ secrets.cloudflare-api-token }} + accountId: ${{ secrets.cloudflare-account-id }} + projectName: ${{ inputs.project-name }} + directory: ./dist + gitHubToken: ${{ steps.app-token.outputs.token }} + branch: ${{ inputs.branch }} + + # https://github.com/marketplace/actions/lighthouse-check + - name: Lighthouse + uses: foo-software/lighthouse-check-action@a80267da2e0244b8a2e457a8575fc47590615852 # v12.0.1 + with: + gitHubAccessToken: ${{ steps.app-token.outputs.token }} + locale: ja + prCommentEnabled: ${{ inputs.pr-comment-enabled }} + urls: ${{ steps.cloudflare-pages.outputs.url }} From 8067a400a803c199434787526a483d3245c7c921 Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Tue, 18 Jun 2024 13:08:10 +0900 Subject: [PATCH 2/2] =?UTF-8?q?ci:=20=E4=B8=8D=E8=A6=81=E3=81=AA=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=83=95=E3=83=AD=E3=83=BC=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd.yml | 7 ----- .github/workflows/wc-release.yml | 54 -------------------------------- 2 files changed, 61 deletions(-) delete mode 100644 .github/workflows/wc-release.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ea4a22f..68decb4 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -10,13 +10,6 @@ concurrency: cancel-in-progress: true jobs: - release: - uses: ./.github/workflows/wc-release.yml - with: - gh-app-id: ${{ vars.BOT_APP_ID }} - secrets: - gh-app-private-key: ${{ secrets.BOT_PRIVATE_KEY }} - deploy: uses: ./.github/workflows/wc-deploy-cloudflare-pages.yml with: diff --git a/.github/workflows/wc-release.yml b/.github/workflows/wc-release.yml deleted file mode 100644 index dba9a43..0000000 --- a/.github/workflows/wc-release.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: 'Release' - -on: - workflow_call: - inputs: - gh-app-id: - required: true - type: string - secrets: - gh-app-private-key: - required: true - outputs: - release-created: - description: "Has the release been created" - value: ${{ jobs.release.outputs.release-created }} - major-tag: - description: "Major version tag" - value: ${{ jobs.release.outputs.major-tag }} - minor-tag: - description: "Minor version tag" - value: ${{ jobs.release.outputs.minor-tag }} - patch-tag: - description: "Patch version tag" - value: ${{ jobs.release.outputs.patch-tag }} - -permissions: - contents: write - pull-requests: write - -jobs: - release: - name: Create new release - runs-on: ubuntu-22.04 - outputs: - release-created: ${{ steps.release.outputs.release_created }} - major-tag: ${{ steps.release.outputs.major }} - minor-tag: ${{ steps.release.outputs.minor }} - patch-tag: ${{ steps.release.outputs.patch }} - steps: - # https://github.com/marketplace/actions/create-github-app-token - - name: Create GitHub App Token - uses: actions/create-github-app-token@c8f55efbd427e7465d6da1106e7979bc8aaee856 # v1.10.1 - id: app-token - with: - app-id: ${{ inputs.gh-app-id }} - private-key: ${{ secrets.gh-app-private-key }} - - - name: Pre release new version - uses: google-github-actions/release-please-action@e4dc86ba9405554aeba3c6bb2d169500e7d3b4ee # v4.1.1 - id: release - with: - token: ${{ steps.app-token.outputs.token }} - config-file: '.github/release-please-config.json' - manifest-file: '.github/release-please-manifest.json'