Skip to content

Commit

Permalink
chore(ci): リリースワークフローの改修
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyme committed Sep 10, 2024
1 parent f421e02 commit bdc4f60
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 1

- name: Enable corepack
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Lint
on:
push:
pull_request:
workflow_call:
workflow_dispatch:

jobs:
Expand Down
257 changes: 237 additions & 20 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,261 @@ on:
workflow_dispatch:
inputs:
bump_type:
description: Select bump type. (v[major].[minor].[patch])
description: Select bump type.
required: true
default: patch
type: choice
options:
- major
- minor
- patch
- specify
specific_version:
description: (If bump type is "specify") Specify version.
required: false

permissions:
contents: read

jobs:
lint:
name: Lint
uses: ./.github/workflows/lint.yaml

parse_version:
name: Parse new version
runs-on: ubuntu-22.04
outputs:
NEW_VERSION: ${{ steps.generate.outputs.NEW_VERSION }}
NEW_TAG: ${{ steps.generate.outputs.NEW_TAG }}
NEW_REF: ${{ steps.generate.outputs.NEW_REF }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 1

- name: Generate new version
id: generate
run: |
cat package.json | jq -r '.version' | IFS='.' read -r major minor patch
if [[ '${{ inputs.bump_type }}' == 'major' ]]; then
new_version="$((major + 1)).0.0"
elif [[ '${{ inputs.bump_type }}' == 'minor' ]]; then
new_version="${major}.$((minor + 1)).0"
elif [[ '${{ inputs.bump_type }}' == 'patch' ]]; then
new_version="${major}.${minor}.$((patch + 1))"
elif [[ '${{ inputs.bump_type }}' == 'specify' ]]; then
new_version="${{ inputs.specific_version }}"
fi
if [[ -z "$new_version" ]]; then
exit 1
fi
echo "NEW_VERSION=${new_version}" >> $GITHUB_OUTPUT
echo "NEW_TAG=v${new_version}" >> $GITHUB_OUTPUT
echo "NEW_REF=ci-release/${new_version}" >> $GITHUB_OUTPUT
create_branch:
name: Create branch
runs-on: ubuntu-22.04
needs:
- lint
- parse_version
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 0

- name: Create branch
run: |
git switch -c ${{ needs.parse_version.outputs.NEW_REF }}
- name: Push branch
run: |
git push origin HEAD
bump_version_update:
name: Bump version (update)
runs-on: ubuntu-22.04
needs:
- parse_version
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 1

- name: Update package.json (root)
run: |
jq '.version = "${{ needs.parse_version.outputs.NEW_VERSION }}"' package.json > tmp
mv tmp package.json
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: bump_version_files
path: |
package.json
bump_version_upload:
name: Bump version (upload)
runs-on: ubuntu-22.04
needs:
- parse_version
- create_branch
- bump_version_update
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.parse_version.outputs.NEW_REF }}
fetch-depth: 1

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bump_version_files

- name: Commit and Push
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Bump up version to ${{ needs.parse_version.outputs.NEW_VERSION }}"
git push origin HEAD
create_pr:
name: Create PR
runs-on: ubuntu-22.04
needs:
- parse_version
- bump_version_upload
outputs:
PR_NUMBER: ${{ steps.create_pr.outputs.CREATED_PR }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.parse_version.outputs.NEW_REF }}
fetch-depth: 0

- name: Create PR
id: create_pr
run: |
CREATED_PR=$(gh pr create --draft --base main --head ${{ needs.parse_version.outputs.NEW_REF }} --title "Release: ${{ needs.parse_version.outputs.NEW_VERSION }}" --body "")
CREATED_PR=$(echo $CREATED_PR | awk -F '/' '/\/pull\/[0-9]+$/ {print $NF}')
echo "CREATED_PR=$CREATED_PR" >> $GITHUB_OUTPUT
merge_pr:
name: Merge PR
runs-on: ubuntu-22.04
needs:
- create_pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 1

- name: Merge PR
run: |
gh pr ready ${{ needs.create_pr.outputs.PR_NUMBER }}
gh pr merge ${{ needs.create_pr.outputs.PR_NUMBER }} --squash --delete-branch --auto
get_merge_commit:
name: Get merge commit
runs-on: ubuntu-22.04
needs:
- create_pr
- merge_pr
outputs:
MERGE_COMMIT: ${{ steps.get_merge_commit.outputs.result }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
pull-requests: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
fetch-depth: 1

- name: Get merge commit
uses: corrupt952/actions-retry-command@v1.0.7
id: get_merge_commit
with:
command: gh pr view ${{ needs.create_pr.outputs.PR_NUMBER }} --json mergeCommit --template '{{ .mergeCommit.oid }}'
working_directory: ${{ github.workspace }}
max_attempts: 10
retry_interval: 10

release:
name: Release
runs-on: ubuntu-22.04
needs:
- parse_version
- get_merge_commit
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.get_merge_commit.outputs.MERGE_COMMIT }}
fetch-depth: 0

- name: Configure environment
- name: Create tag
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag ${{ needs.parse_version.outputs.NEW_TAG }} ${{ needs.get_merge_commit.outputs.MERGE_COMMIT }}
git push origin ${{ needs.parse_version.outputs.NEW_TAG }}
- name: Create Release
run: |
gh release create ${{ needs.parse_version.outputs.NEW_TAG }} --generate-notes
publish:
name: Publish
runs-on: ubuntu-22.04
needs:
- get_merge_commit
- release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.get_merge_commit.outputs.MERGE_COMMIT }}
fetch-depth: 0

- name: Configure environment
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Enable corepack
Expand All @@ -42,31 +271,19 @@ jobs:
node-version-file: .node-version
cache: pnpm

- name: Bump up version
run: |
pnpm version ${{ github.event.inputs.bump_type }} -m "v%s"
- name: Publish
- name: Install dependencies
run: |
pnpm install --frozen-lockfile --ignore-scripts
pnpm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Release
- name: Publish
run: |
VERSION=$(git describe --tags --abbrev=0)
git push origin HEAD
git push origin $VERSION
gh release create $VERSION --generate-notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pnpm publish --provenance --no-git-checks --access public
deploy_page:
deploy:
name: Deploy to GitHub Pages
needs:
- release
permissions:
pages: write
id-token: write
needs:
- release
uses: ./.github/workflows/deploy.yaml

0 comments on commit bdc4f60

Please sign in to comment.