chore(deps): update linter families (major) #1510
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cloudflare Pages | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
publish: | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: read | |
deployments: write | |
statuses: write | |
# mainブランチのときは"aska (Production)"、それ以外のときは"aska (Preview)" | |
environment: ${{ github.ref == 'refs/heads/main' && 'aska (Production)' || 'aska (Preview)' }} | |
env: | |
NEXT_PUBLIC_MICROCMS_ENDPOINT: ${{ vars.NEXT_PUBLIC_MICROCMS_ENDPOINT }} | |
# もしmainブランチから別環境へのブランチを作成する場合、このjobは走らせない | |
if: ${{ !(github.event_name == 'pull_request' && github.head_ref == 'main') }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
- run: corepack enable | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn config get cacheFolder)" | |
- uses: actions/cache@v4 | |
id: yarn-cache | |
with: | |
path: | | |
${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
run: yarn install --frozen-lockfile | |
- uses: actions/cache@v4 | |
id: next-export-optimize-images-cache | |
with: | |
path: | | |
${{ github.workspace }}/node_modules/.cache/next-export-optimize-images | |
key: ${{ runner.os }}-2-next-export-optimize-images-cache-${{ hashFiles('src/**/*') }}-${{ hashFiles('public/**/*') }} | |
restore-keys: | | |
${{ runner.os }}-2-next-export-optimize-images-cache- | |
- uses: actions/cache@v4 | |
id: dot-next-cache | |
with: | |
path: | | |
${{ github.workspace }}/.next | |
key: ${{ runner.os }}-2-next-dir-${{ hashFiles('src/**/*') }}-${{ hashFiles('public/**/*') }} | |
restore-keys: | | |
${{ runner.os }}-2-next-dir- | |
- name: Build | |
run: yarn export | |
- name: Publish to Cloudflare Pages | |
id: cloudflare_pages_deploy | |
uses: cloudflare/pages-action@1 | |
with: | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
projectName: aska | |
directory: ./out | |
gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.head_ref || github.ref_name }} | |
- name: Get retry count from last commit | |
if: steps.cloudflare_pages_deploy.outcome == 'failure' | |
id: get_last_commit_retry_count | |
run: | | |
echo "::set-output name=retry_count::$(git log --format=%B -n 1 | grep -oP 'ci: run \K\d+')" | |
- name: Empty commit | |
if: steps.cloudflare_pages_deploy.outcome == 'failure' && github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.get_last_commit_retry_count.outputs.retry_count < 10 | |
uses: ./.github/workflows/commit-empty.yml | |
with: | |
count: ${{ (steps.get_last_commit_retry_count.outputs.retry_count != '' && steps.get_last_commit_retry_count.outputs.retry_count ) || 1 }} | |
- name: Outputs | |
run: | | |
echo "ID: ${{ steps.cloudflare_pages_deploy.outputs.id }}" | |
echo "URL: ${{ steps.cloudflare_pages_deploy.outputs.url }}" | |
echo "Environment: ${{ steps.cloudflare_pages_deploy.outputs.environment }}" | |
echo "Alias: ${{ steps.cloudflare_pages_deploy.outputs.alias }}" | |
- name: Add publish URL as commit status | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const target_url = "${{ steps.cloudflare_pages_deploy.outputs.url }}"; | |
const sha = context.payload.pull_request?.head.sha ?? context.sha; | |
await github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
context: 'Cloudflare Pages', | |
description: 'Cloudflare Pages deployment', | |
state: 'success', | |
sha, | |
target_url, | |
}); | |
const url_obj = new URL(target_url); | |
const alias_host = [ | |
"${{ github.head_ref || github.ref_name }}".replace(/[^a-z0-9]/ig, "-"), | |
...url_obj.host.split(".").slice(1) | |
].join("."); | |
url_obj.host = alias_host; | |
await github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
context: 'Cloudflare Pages Alias', | |
description: 'Cloudflare Pages deployment alias', | |
state: 'success', | |
sha, | |
target_url: url_obj.toString(), | |
}); |