Skip to content

Commit

Permalink
Merge pull request #18 from aodn/semantic-release
Browse files Browse the repository at this point in the history
Create semantic-release-ci.yml
  • Loading branch information
shaunahu authored Oct 30, 2024
2 parents fa893af + 67898e8 commit 5010e27
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/semantic-release-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Semantic Release CI

on:
push:
branches:
- main
paths-ignore:
- '**/*.md'

permissions:
contents: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm install semantic-release @semantic-release/exec @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/github

- name: Run semantic-release and extract changelog
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Generate changelog with Markdown formatting by running semantic-release in dry-run mode
npx semantic-release --dry-run | tee semantic_output.log
# Capture the changelog markdown from semantic-release output for the latest version
changelog=$(awk '/Release note for version/ {flag=1; next} flag && !/^#[^#]/' semantic_output.log)
# Insert "v" in front of version numbers in `##` headers
changelog=$(echo "$changelog" | sed -E 's/^## ([0-9]+\.[0-9]+\.[0-9]+)/## v\1/')
# Trim leading spaces before each bullet point (lines starting with `* `)
changelog=$(echo "$changelog" | sed -E 's/^[[:space:]]+\*/\*/')
# Write the cleaned changelog to a file
echo "$changelog" > changelog.md
# Set the changelog as an output variable for use in the GitHub release step
echo "changelog<<EOF" >> $GITHUB_ENV
echo "$changelog" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Push new tag
if: ${{ steps.release.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version="${{ steps.release.outputs.version }}"
# Create and push the new tag
git tag "$version"
git push origin "$version"
- name: Create GitHub Release with Changelog
if: ${{ steps.release.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version="${{ steps.release.outputs.version }}"
tag_name="$version"
# Read changelog from the markdown file to preserve formatting
release_notes=$(<changelog.md)
# Create GitHub release with formatted markdown changelog
gh release create "$tag_name" \
--title "$version" \
--notes "$release_notes" \
--target main \
--draft
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,15 @@ The configurations for pre-commit hooks are defined in `.pre-commit-config.yaml`
```shell
pre-commit run --all-files
```

### Versioning

This project uses **semantic versioning** with automated releases managed by `semantic-release`.

Every code change with commits following [Conventional Commits](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional) will trigger a version update and create a GitHub release.

**Commit Guidelines**

* `feat:` For new features
* `fix:` For bug fixes
* `BREAKING CHANGE:` For any breaking changes

0 comments on commit 5010e27

Please sign in to comment.