Open2
📝 GitHub Pages にデプロイする時の Github Actions メモ
ピン留めされたアイテム
🚚 mainブランチが更新されたら、GitHubPagesにデプロイします。
name: deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2.0.1
with:
version: 7.0.0
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version-file: ".node-version"
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Run test
run: pnpm test
- name: Build App
run: pnpm build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
release/**
ブランチをmainブランチにマージする時、マージコミットにバージョンタグを作成します。
🏷 name: ci
on:
pull_request
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2.0.1
with:
version: 7.0.0
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version-file: ".node-version"
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Run test
run: |
pnpm type-check
pnpm lint
pnpm test
🔧 プルリクエストを作成した時にCIを実行する。
name: release-tag
on:
pull_request:
branches:
- main
types:
- closed
jobs:
main:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/')
steps:
- uses: actions/checkout@v2
- name: Create Tag
id: create-tag
run: |
git fetch origin main
git checkout main
echo '${{ github.event.pull_request.head.ref }}' | sed 's/release\///' > TAG_NAME
git tag $(cat TAG_NAME)
git push origin $(cat TAG_NAME)
echo "::set-output name=tag-name::$(cat TAG_NAME)"
- name: Create Release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.create-tag.outputs.tag-name }}
release_name: Release ${{ steps.create-tag.outputs.tag-name }}
body: |
Changes in this Release
- First Change
- Second Change
draft: false
prerelease: false
サンプルpackage.json
{
"name": "example-scripts",
"private": true,
"version": "0.1.0",
"scripts": {
"dev": "vite",
"build": "pnpm type-check && vite build",
"preview": "vite preview",
"lint": "eslint . --ext .ts,.js",
"format": "prettier --config .prettierrc.json --write './**/*.{ts,js,md}'",
"fix": "pnpm format && pnpm lint --fix",
"test": "vitest run",
"type-check": "tsc",
}
}