build_release #10
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: build_release | |
on: | |
schedule: | |
- cron: '0 19 */3 * *' | |
workflow_dispatch: | |
jobs: | |
build_release: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
changes_detected: ${{ steps.changes.outputs.changed }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get previous tag or default to changed=true | |
id: previous_tag | |
run: | | |
prev_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "none") | |
if [ "$prev_tag" == "none" ]; then | |
echo "No tags found. Setting changed=true by default." | |
echo "changed=true" >> $GITHUB_ENV | |
else | |
echo "Previous tag: $prev_tag" | |
echo "previous_tag=$prev_tag" >> $GITHUB_ENV | |
fi | |
- name: Check for changes between previous tag and latest commit in src directory | |
id: changes | |
run: | | |
if [ "$prev_tag" != "none" ]; then | |
if git diff --exit-code ${{ env.previous_tag }} HEAD -- src; then | |
echo "No changes detected in 'src' directory between ${{ env.previous_tag }} and the latest commit." | |
echo "changed=false" >> $GITHUB_ENV | |
else | |
echo "Changes detected in 'src' directory between ${{ env.previous_tag }} and the latest commit." | |
echo "changed=true" >> $GITHUB_ENV | |
fi | |
fi | |
- name: Terminate if no changes detected | |
if: env.changed != 'true' | |
run: | | |
echo "No changes in 'src' directory, terminating the workflow." | |
exit 1 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- uses: pnpm/action-setup@v4 | |
- run: pnpm install | |
- run: pnpm run build | |
- id: version | |
run: | | |
version=$(node -e "import('@gkd-kit/tools').then((m) => m.stdoutGkdVersion());") | |
echo "version=${version}" >> "$GITHUB_OUTPUT" | |
- id: update_pkg_version | |
run: node -e "import('@gkd-kit/tools').then((m) => m.updatePkgVersion());" | |
- name: Git commit | |
id: commit | |
run: | | |
git config --local user.email github-actions[bot]@users.noreply.github.com | |
git config --local user.name github-actions[bot] | |
git status | |
git add . | |
git commit -a -m "chore: v${{steps.version.outputs.version}}" | |
continue-on-error: true | |
- name: Git push | |
if: ${{ steps.commit.outcome == 'success' }} | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.ref }} | |
tags: true | |
- name: Create Release | |
id: create_release | |
if: ${{ steps.commit.outcome == 'success' }} | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.version.outputs.version }} | |
release_name: Release ${{ steps.version.outputs.version }} | |
body_path: ./dist/CHANGELOG.md | |
- name: Publish package | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
if: ${{ steps.commit.outcome == 'success' && env.NPM_TOKEN != '' }} | |
run: | | |
pnpm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} | |
pnpm publish --no-git-checks | |
node -e "import('@gkd-kit/tools').then((m) => m.syncNpmmirror());" |