feat: logger level #112
This file contains hidden or 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: Release | |
| on: | |
| push: | |
| branch: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: write # Needed for checkout and release creation | |
| jobs: | |
| check_version: | |
| name: Check Version Change | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_release: ${{ steps.check_version.outputs.should_release }} | |
| version: ${{ steps.get_package_version.outputs.version }} # Pass version to next job | |
| tag_name: v${{ steps.get_package_version.outputs.version }} # Pass tag name to next job | |
| # Only run if the commit message doesn't contain '[skip release]' | |
| if: "!contains(github.event.head_commit.message, '[skip release]')" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' # Match the version used in other workflows | |
| - name: Get version from package.json | |
| id: get_package_version | |
| run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| - name: Get latest release tag name | |
| id: get_latest_tag | |
| # Use gh cli to get the latest release tag. Handle errors if no releases exist. | |
| run: | | |
| latest_tag=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' || echo "") | |
| echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check if release should be created | |
| id: check_version | |
| run: | | |
| current_tag="v${{ steps.get_package_version.outputs.version }}" | |
| latest_tag="${{ steps.get_latest_tag.outputs.latest_tag }}" | |
| if [ "$current_tag" != "$latest_tag" ]; then | |
| echo "Version Changed ($latest_tag -> $current_tag). Need to Release." | |
| echo "should_release=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version $current_tag matches latest release tag $latest_tag. No Need to Release." | |
| echo "should_release=false" >> $GITHUB_OUTPUT | |
| fi | |
| create_release: | |
| name: Create GitHub Release | |
| needs: check_version | |
| if: needs.check_version.outputs.should_release == 'true' # Only run if version changed | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Need write access to create release/tag | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Needed for changelog generator | |
| - name: Generate Release note body. | |
| id: github_release | |
| uses: mikepenz/release-changelog-builder-action@v5 | |
| with: | |
| mode: "HYBRID" | |
| # Explicitly define the range: from the last release tag to the current commit SHA | |
| fromTag: ${{ steps.get_latest_tag.outputs.latest_tag }} | |
| toTag: ${{ github.sha }} | |
| configurationJson: | | |
| { | |
| "categories": [ | |
| { | |
| "title": "## Feature", | |
| "labels": ["feat", "feature", "Feat", "Feature"] | |
| }, | |
| { | |
| "title": "## Fix", | |
| "labels": ["fix", "bug", "Fix", "Bug"] | |
| }, | |
| { | |
| "title": "## Performance", | |
| "labels": ["perf","Perf"] | |
| }, | |
| { | |
| "title": "## Documentation", | |
| "labels": ["docs","Docs"] | |
| }, | |
| { | |
| "title": "## Chore", | |
| "labels": ["chore","Chore"] | |
| }, | |
| { | |
| "title": "## Refactor", | |
| "labels": ["refactor","Refactor"] | |
| }, | |
| { | |
| "title": "## Revert", | |
| "labels": ["revert","Revert"] | |
| }, | |
| { | |
| "title": "## Style", | |
| "labels": ["style","Style"] | |
| }, | |
| { | |
| "title": "## Test", | |
| "labels": ["test","Test"] | |
| }, | |
| { | |
| "title": "## Other", | |
| "labels": [] | |
| } | |
| ], | |
| "label_extractor": [ | |
| { | |
| "pattern": "^(build|Build|chore|Chore|ci|Ci|docs|Docs|feat|Feat|feature|Feature|bug|Bug|fix|Fix|perf|Perf|refactor|Refactor|revert|Revert|style|Style|test|Test){1}(\\([\\w\\-\\.]+\\))?(!)?: ([\\w ])+([\\s\\S]*)", | |
| "on_property": "title", | |
| "target": "$1" | |
| } | |
| ] | |
| } | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 # Using softprops action | |
| with: | |
| tag_name: ${{ needs.check_version.outputs.tag_name }} | |
| name: Release ${{ needs.check_version.outputs.tag_name }} | |
| body: ${{ steps.github_release.outputs.changelog }} # Use generated changelog from the correct step ID | |
| # Optional: Mark as pre-release if version contains '-' | |
| # prerelease: ${{ contains(needs.check_version.outputs.version, '-') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |