Publish #3
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: Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
versionType: | |
type: choice | |
description: '<major|minor|patch>' | |
required: true | |
default: 'minor' | |
options: | |
- major | |
- minor | |
- patch | |
jobs: | |
publish: | |
name: Publish ${{ inputs.versionType }} release | |
permissions: | |
# Give the default GITHUB_TOKEN write permission to commit and push the | |
# added or changed files to the repository. | |
contents: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_ACCESS_TOKEN }} | |
- name: Prepare Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ vars.NODE_VERSION}} | |
- id: update-version | |
shell: bash | |
name: Update package.json version | |
# Use npm because yarn is for some reason not able to output only the version name | |
run: | | |
echo "version=$(npm version --no-git-tag-version ${{ inputs.versionType }})" >> $GITHUB_OUTPUT | |
git add . | |
- uses: planetscale/[email protected] | |
name: Commit new version | |
with: | |
commit_message: "🤖 Release ${{steps.update-version.outputs.version}}" | |
repo: ${{ github.repository }} | |
branch: main | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: pnpm/action-setup@v2 | |
name: Install pnpm | |
with: | |
version: 8 | |
run_install: false | |
- name: Get pnpm store directory | |
shell: bash | |
run: | | |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
- uses: actions/cache@v3 | |
name: Setup pnpm cache | |
with: | |
path: ${{ env.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: Checkout release branch | |
shell: bash | |
run: | | |
git checkout -b release/${{steps.update-version.outputs.version}} | |
git push origin release/${{steps.update-version.outputs.version}} | |
- name: Install | |
run: pnpm i | |
- name: Build | |
run: pnpm run build | |
- name: Install prod dependencies | |
run: rm -rf node_modules && pnpm install --production | |
- name: Add node_modules and dist | |
shell: bash | |
run: | | |
git add --force dist/ | |
- uses: planetscale/[email protected] | |
name: Commit dist | |
with: | |
commit_message: "🤖 Build ${{steps.update-version.outputs.version}}" | |
repo: ${{ github.repository }} | |
branch: release/${{steps.update-version.outputs.version}} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create tag | |
id: tag | |
shell: bash | |
run: | | |
git tag ${{steps.update-version.outputs.version}} | |
git push origin ${{steps.update-version.outputs.version}} | |
git push origin --delete release/${{steps.update-version.outputs.version}} | |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
- name: 'Build Changelog' | |
id: build_changelog | |
uses: mikepenz/release-changelog-builder-action@v4 | |
with: | |
token: '${{ github.token }}' | |
configurationJson: | | |
{ | |
"categories": [ | |
{ | |
"title": "## 🚀 Features", | |
"labels": ["feature"] | |
}, | |
{ | |
"title": "## 🐛 Fixes", | |
"labels": ["fix"] | |
}, | |
{ | |
"title": "## 💬 Other", | |
"labels": ["other"] | |
}, | |
{ | |
"title": "## 📦 Dependencies", | |
"labels": ["dependencies"] | |
}, | |
{ | |
"title": "## ❓ Uncategorized", | |
"labels": [] | |
} | |
] | |
} | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
draft: true | |
body: ${{steps.build_changelog.outputs.changelog}} | |
name: ${{steps.update-version.outputs.version}} | |
tag_name: ${{steps.update-version.outputs.version}} | |
target_commitish: ${{ steps.tag.outputs.sha }} |