Skip to content

Fix: Document CI process and some issues #42

Fix: Document CI process and some issues

Fix: Document CI process and some issues #42

Workflow file for this run

name: Build and Release
on:
push:
branches: ["main"]
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js and pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Get commit message
id: commit_message
run: echo "MESSAGE=$(git log --format=%B -n 1 ${{ github.sha }})" >> $GITHUB_ENV
- name: Install yq via Snap
run: sudo apt install snapd && sudo snap install yq
- name: Parse commit message and update version
id: update_version
run: |
COMMIT_MESSAGE="${{ env.MESSAGE }}"
CURRENT_VERSION=$(cat .github/version.yml | yq eval '.version' -)
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
if [[ $COMMIT_MESSAGE == "First"* ]]; then
MAJOR=1
MINOR=0
PATCH=0
elif [[ $COMMIT_MESSAGE == "Fix"* ]]; then
PATCH=$((PATCH + 1))
elif [[ $COMMIT_MESSAGE == "Feat"* ]]; then
MINOR=$((MINOR + 1))
PATCH=0
elif [[ $COMMIT_MESSAGE == "Refactor"* ]]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
else
echo "No version update needed for other commit types."
echo "NEW_VERSION=null" >> $GITHUB_ENV
exit 0
fi
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "Updating version from $CURRENT_VERSION to $NEW_VERSION"
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
- name: Stop if no version update
if: env.NEW_VERSION == 'null'
run: echo "No version update needed. Stopping workflow."
- name: Update version.yml
if: env.NEW_VERSION != 'null'
run: |
yq eval ".version = \"$NEW_VERSION\"" -i .github/version.yml
- name: Commit updated version.yml
if: env.NEW_VERSION != 'null'
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add .github/version.yml
git commit -m "chore: update version to $NEW_VERSION"
git push
- name: Create Release
id: create_release
uses: actions/create-release@v1
if: env.NEW_VERSION != 'null'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.NEW_VERSION }}
release_name: Release ${{ env.NEW_VERSION }}
draft: false
prerelease: false