|
| 1 | +--- |
| 2 | +name: 🚀 Conventional Commits Release |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + target_branch: |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + default: master |
| 11 | + description: 'Target branch for releases' |
| 12 | + initial_version: |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: "1.0.0" |
| 16 | + description: 'Initial version if no tags exist' |
| 17 | + prerelease: |
| 18 | + required: false |
| 19 | + type: boolean |
| 20 | + default: false |
| 21 | + description: 'Create prerelease versions' |
| 22 | + changelog_file: |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + default: "CHANGELOG.md" |
| 26 | + description: 'Changelog file path' |
| 27 | + version_prefix: |
| 28 | + required: false |
| 29 | + type: string |
| 30 | + default: "v" |
| 31 | + description: 'Version prefix (e.g., v for v1.0.0)' |
| 32 | + secrets: |
| 33 | + GITHUB_TOKEN: |
| 34 | + required: true |
| 35 | + description: 'GitHub token for creating releases and tags' |
| 36 | + |
| 37 | +jobs: |
| 38 | + conventional-release: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', inputs.target_branch) |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: 📦 Checkout repository |
| 44 | + uses: actions/checkout@v5 |
| 45 | + with: |
| 46 | + fetch-depth: 0 |
| 47 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + - name: đź§© Install dependencies |
| 50 | + run: | |
| 51 | + sudo apt-get update |
| 52 | + sudo apt-get install -y jq |
| 53 | +
|
| 54 | + - name: 🔍 Determine next version |
| 55 | + id: version |
| 56 | + |
| 57 | + with: |
| 58 | + write-tag: false |
| 59 | + initial-version: ${{ inputs.initial_version }} |
| 60 | + prerelease: ${{ inputs.prerelease }} |
| 61 | + version-prefix: ${{ inputs.version_prefix }} |
| 62 | + |
| 63 | + - name: 📝 Generate changelog |
| 64 | + id: changelog |
| 65 | + uses: requarks/changelog-action@v1 |
| 66 | + with: |
| 67 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + tag: ${{ steps.version.outputs.version }} |
| 69 | + includeInvalidCommits: false |
| 70 | + writeToFile: true |
| 71 | + changelogFilePath: ${{ inputs.changelog_file }} |
| 72 | + includeRefIssues: true |
| 73 | + useGitmojis: true |
| 74 | + reverseOrder: false |
| 75 | + |
| 76 | + - name: 🏷️ Create and push tag |
| 77 | + if: steps.version.outputs.version != '' |
| 78 | + run: | |
| 79 | + git config user.name "clouddrove-ci" |
| 80 | + git config user.email "[email protected]" |
| 81 | + git tag ${{ steps.version.outputs.version }} |
| 82 | + git push origin ${{ steps.version.outputs.version }} |
| 83 | +
|
| 84 | + - name: 🚀 Create GitHub release |
| 85 | + if: steps.version.outputs.version != '' |
| 86 | + uses: ncipollo/release-action@v1 |
| 87 | + with: |
| 88 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + tag: ${{ steps.version.outputs.version }} |
| 90 | + name: ${{ steps.version.outputs.version }} |
| 91 | + allowUpdates: true |
| 92 | + draft: false |
| 93 | + prerelease: ${{ inputs.prerelease }} |
| 94 | + makeLatest: true |
| 95 | + body: | |
| 96 | + ${{ steps.changelog.outputs.changes }} |
| 97 | +
|
| 98 | + **Release Type:** ${{ steps.version.outputs.version_type }} |
| 99 | +
|
| 100 | + [Compare changes](https://github.com/${{ github.repository }}/compare/${{ steps.version.outputs.previous_version }}...${{ steps.version.outputs.version }}) |
| 101 | +
|
| 102 | + - name: đź’ľ Commit changelog |
| 103 | + if: steps.version.outputs.version != '' |
| 104 | + uses: stefanzweifel/git-auto-commit-action@v6 |
| 105 | + with: |
| 106 | + branch: ${{ inputs.target_branch }} |
| 107 | + commit_user_name: clouddrove-ci |
| 108 | + commit_user_email: [email protected] |
| 109 | + commit_author: "CloudDrove CI <[email protected]>" |
| 110 | + commit_message: 'docs: update ${{ inputs.changelog_file }} for ${{ steps.version.outputs.version }}' |
| 111 | + file_pattern: ${{ inputs.changelog_file }} |
| 112 | + |
| 113 | + - name: đź“‹ Release summary |
| 114 | + run: | |
| 115 | + if [ -n "${{ steps.version.outputs.version }}" ]; then |
| 116 | + echo "âś… Released ${{ steps.version.outputs.version }} successfully" |
| 117 | + echo "🏷️ Version type: ${{ steps.version.outputs.version_type }}" |
| 118 | + echo "📝 Changelog updated: ${{ inputs.changelog_file }}" |
| 119 | + if [ "${{ inputs.prerelease }}" == "true" ]; then |
| 120 | + echo "đź”– This is a prerelease" |
| 121 | + fi |
| 122 | + else |
| 123 | + echo "ℹ️ No new version to release" |
| 124 | + fi |
0 commit comments