add blog #334
Workflow file for this run
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: CI | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: .node-version | |
cache: npm | |
- run: npm ci | |
- uses: actions/cache@v3 | |
with: | |
path: dist/cache | |
key: ${{ runner.os }}-astro-build-${{ github.event_name == 'pull_request' && github.event.pull_request.id || 'main' }} | |
restore-keys: ${{ runner.os }}-astro-build- | |
- run: npm run build | |
- uses: actions/upload-pages-artifact@v1 | |
if: github.ref == 'refs/heads/main' | |
with: | |
path: dist/out | |
retention-days: 90 | |
lint: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: .node-version | |
cache: npm | |
- run: npm ci | |
- run: npm run lint | |
typecheck: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: .node-version | |
cache: npm | |
- run: npm ci | |
- run: npm run typecheck | |
validate-blog: | |
if: startsWith(github.head_ref, 'blog/') && !startsWith(github.head_ref, 'blog/admin/') && github.actor != 'oucc-blog-ci[bot]' | |
# Lintは環境構築していない人のことを考えてCIで行う | |
needs: [typecheck, build] | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: .node-version | |
cache: npm | |
- run: npm ci | |
- run: | | |
git fetch origin main | |
git diff origin/main..HEAD --name-only | xargs npm run validate-blog -- | |
update-blogmeta: | |
needs: [validate-blog] | |
permissions: | |
contents: write | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/create-github-app-token@v1 | |
id: generate-token | |
with: | |
app-id: ${{ secrets.APP_ID }} | |
private-key: ${{ secrets.PRIVATE_KEY }} | |
- uses: actions/checkout@v4 | |
# Checkout pull request HEAD commit instead of merge commit | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
token: ${{ steps.generate-token.outputs.token }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: .node-version | |
cache: npm | |
- run: npm ci | |
- name: Update Blog Meta | |
run: | | |
git fetch origin main | |
git diff origin/main..HEAD --name-status | xargs npm run update-blogmeta -- | |
- run: npm run format | |
- name: Git Commit | |
run: | | |
git add -N . | |
if ! git diff --exit-code --quiet | |
then | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add . | |
git commit -m "[Bot] Update Blog Meta" | |
git push | |
fi | |
deploy: | |
if: github.ref == 'refs/heads/main' | |
needs: [build, lint, typecheck] | |
permissions: | |
pages: write | |
id-token: write | |
concurrency: | |
group: 'pages' | |
cancel-in-progress: false | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v1 |