Skip to content

fix(ci): re-enabled with the proper changes. #32

fix(ci): re-enabled with the proper changes.

fix(ci): re-enabled with the proper changes. #32

Workflow file for this run

name: Automatic Semantic Versioning
# Restrict the workflow to the main branch and ignore tags
on:
workflow_dispatch:
push:
branches:
- main
jobs:
tag_version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
- name: Initialize NPM
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm install
- name: Semantic Versioning
id: get_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Run semantic-release in dry-run mode and capture the next version and changelog notes
node -e "
const fs = require('fs');
const semanticRelease = require('semantic-release');
(async () => {
const result = await semanticRelease({
dryRun: true,
ci: false,
branches: ['main'],
repositoryUrl: 'https://github.com/${{ github.repository }}',
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
],
});
console.log('Result:', result);
if (result && result.nextRelease) {
const changelogNotes = JSON.stringify(result.nextRelease.notes);
console.log('Next version:', result.nextRelease.version);
console.log('Changelog:', changelogNotes);
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'new_version=' + result.nextRelease.version + '\n');
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'changelog=' + changelogNotes + '\n');
} else {
console.log('No release necessary.');
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'new_version=\n');
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'changelog=\n');
}
})();
"
- name: Configure Git
if: ${{ steps.get_version.outputs.new_version != '' }}
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Create Release Commit
if: ${{ steps.get_version.outputs.new_version != '' }}
env:
NEW_VERSION: ${{ steps.get_version.outputs.new_version }}
CHANGELOG: ${{ steps.get_version.outputs.changelog }}
run: |
# Output everything.
echo "New version: $NEW_VERSION"
echo "Changelog: $CHANGELOG"
# Create the commit message
COMMIT_MSG="chore(release): v$NEW_VERSION"
# Create an empty commit with the changelog as the commit body
git commit --allow-empty -m "$COMMIT_MSG" -m "$CHANGELOG"
# Push the commit back to the branch
git push origin HEAD:${{ github.ref }}
# Create a new tag for the release
git tag -a "v$NEW_VERSION" -m "Release version $NEW_VERSION" -m "$CHANGELOG"
git push origin "v$NEW_VERSION"