diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 6929e17..68decb4 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -10,9 +10,14 @@ concurrency: cancel-in-progress: true jobs: - release: - uses: ./.github/workflows/wc-release.yml + 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 }} 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'