|
| 1 | +name: Git Deployer Tag and Release |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + branch: |
| 6 | + description: 'Branch to tag (e.g. main)' |
| 7 | + required: true |
| 8 | + default: 'main' |
| 9 | + new_tag: |
| 10 | + description: 'New version tag (e.g. v1.2.0)' |
| 11 | + required: true |
| 12 | + moving_tag: |
| 13 | + description: 'Moving tag to update (e.g. v1)' |
| 14 | + required: false |
| 15 | + default: '' |
| 16 | + create_release: |
| 17 | + description: 'Create GitHub release? (yes/no)' |
| 18 | + required: true |
| 19 | + default: 'no' |
| 20 | + options: |
| 21 | + - 'yes' |
| 22 | + - 'no' |
| 23 | + release_title: |
| 24 | + description: 'Title for the release (if created)' |
| 25 | + required: false |
| 26 | + default: '' |
| 27 | + |
| 28 | +jobs: |
| 29 | + tag-and-release: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + permissions: |
| 32 | + contents: write # Required for tagging and releasing |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout repo |
| 36 | + uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + fetch-depth: 0 # Important for full git history |
| 39 | + |
| 40 | + - name: Configure Git |
| 41 | + run: | |
| 42 | + git config user.name "github-actions" |
| 43 | + git config user.email "[email protected]" |
| 44 | +
|
| 45 | + - name: Create new tag |
| 46 | + run: | |
| 47 | + git fetch origin ${{ github.event.inputs.branch }} |
| 48 | + git checkout ${{ github.event.inputs.branch }} |
| 49 | + git tag ${{ github.event.inputs.new_tag }} |
| 50 | + git push origin ${{ github.event.inputs.new_tag }} |
| 51 | +
|
| 52 | + - name: Update moving tag |
| 53 | + if: ${{ github.event.inputs.moving_tag != '' }} |
| 54 | + run: | |
| 55 | + git tag -f ${{ github.event.inputs.moving_tag }} ${{ github.event.inputs.new_tag }} |
| 56 | + git push -f origin ${{ github.event.inputs.moving_tag }} |
| 57 | +
|
| 58 | + - name: Get previous tag |
| 59 | + id: prev-tag |
| 60 | + run: | |
| 61 | + PREV_TAG=$(git tag --sort=-creatordate | grep -v "${{ github.event.inputs.new_tag }}" | head -n 1) |
| 62 | + echo "Previous tag: $PREV_TAG" |
| 63 | + echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT |
| 64 | +
|
| 65 | + - name: Generate changelog |
| 66 | + id: changelog |
| 67 | + run: | |
| 68 | + if [ -z "${{ steps.prev-tag.outputs.tag }}" ]; then |
| 69 | + echo "No previous tag found, using initial commit." |
| 70 | + CHANGELOG=$(git log --pretty=format:"- %s" ${{ github.event.inputs.new_tag }}) |
| 71 | + else |
| 72 | + CHANGELOG=$(git log --pretty=format:"- %s" ${{ steps.prev-tag.outputs.tag }}..${{ github.event.inputs.new_tag }}) |
| 73 | + fi |
| 74 | + echo "CHANGELOG<<EOF" >> $GITHUB_ENV |
| 75 | + echo "$CHANGELOG" >> $GITHUB_ENV |
| 76 | + echo "EOF" >> $GITHUB_ENV |
| 77 | +
|
| 78 | + - name: Create GitHub Release with changelog |
| 79 | + if: ${{ github.event.inputs.create_release == 'yes' }} |
| 80 | + uses: softprops/action-gh-release@v1 |
| 81 | + with: |
| 82 | + tag_name: ${{ github.event.inputs.new_tag }} |
| 83 | + name: ${{ github.event.inputs.release_title || github.event.inputs.new_tag }} |
| 84 | + body: ${{ env.CHANGELOG }} |
| 85 | + env: |
| 86 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments