Skip to content

Commit

Permalink
Add semantic release
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyengit committed Dec 10, 2024
1 parent 26b6012 commit b17cd6c
Show file tree
Hide file tree
Showing 6 changed files with 6,989 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version = 1

[[analyzers]]
name = "python"

[analyzers.meta]
runtime_version = "3.x.x"
75 changes: 75 additions & 0 deletions .github/workflows/semantic-release-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Semantic Release CI
on:
pull_request:
branches:
- main
push:
branches:
- main
paths-ignore:
- '**/*.md'
- '.github/environment/**'
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ dmypy.json
cython_debug/
.idea
*.iml
node_modules/
18 changes: 18 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/github",
[
"@semantic-release/exec", {
"verifyReleaseCmd": "echo \"version=v${nextRelease.version}\" >> $GITHUB_OUTPUT"
}
]
],
"preset": "angular",
"tagFormat": "v${version}"
}
Loading

0 comments on commit b17cd6c

Please sign in to comment.