|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag_name: |
| 10 | + description: 'Tag name for the release' |
| 11 | + required: true |
| 12 | + default: 'v1.0.0' |
| 13 | + release_type: |
| 14 | + description: 'Release type (stable, beta, rc)' |
| 15 | + required: true |
| 16 | + default: 'stable' |
| 17 | + |
| 18 | +jobs: |
| 19 | + release: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v3 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Install GitHub CLI |
| 29 | + run: | |
| 30 | + sudo apt-get update |
| 31 | + sudo apt-get install -y gh |
| 32 | +
|
| 33 | + - name: Authenticate GitHub CLI |
| 34 | + env: |
| 35 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + run: gh auth setup-git |
| 37 | + |
| 38 | + - name: Determine release type |
| 39 | + id: release_type |
| 40 | + run: | |
| 41 | + TAG_NAME=${{ github.ref_name }} |
| 42 | + if [[ "$TAG_NAME" == *beta* ]]; then |
| 43 | + echo "release_type=Pre-release (Beta)" >> $GITHUB_ENV |
| 44 | + echo "prerelease=true" >> $GITHUB_ENV |
| 45 | + elif [[ "$TAG_NAME" == *rc* ]]; then |
| 46 | + echo "release_type=Pre-release (Release Candidate)" >> $GITHUB_ENV |
| 47 | + echo "prerelease=true" >> $GITHUB_ENV |
| 48 | + else |
| 49 | + echo "release_type=Stable" >> $GITHUB_ENV |
| 50 | + echo "prerelease=false" >> $GITHUB_ENV |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Get commits since last tag |
| 54 | + id: commits |
| 55 | + run: | |
| 56 | + PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") |
| 57 | + if [ -z "$PREV_TAG" ]; then |
| 58 | + echo "No previous tag found, using initial commit." |
| 59 | + COMMITS=$(git log --format="- %s (@%an)" HEAD) |
| 60 | + else |
| 61 | + COMMITS="" |
| 62 | + while read -r commit_hash; do |
| 63 | + COMMIT_MSG=$(git log -n 1 --pretty=format:"%s" "$commit_hash") |
| 64 | + AUTHOR=$(gh api "/repos/${{ github.repository }}/commits/$commit_hash" --jq '.author.login') |
| 65 | + COMMITS+="- $COMMIT_MSG (@$AUTHOR)" |
| 66 | + COMMITS+=$'\n' |
| 67 | + done < <(git log --format="%H" $PREV_TAG..HEAD) |
| 68 | + fi |
| 69 | + |
| 70 | + echo "commits=$COMMITS" >> $GITHUB_ENV |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + |
| 74 | + - name: Create release |
| 75 | + uses: ncipollo/release-action@v1 |
| 76 | + env: |
| 77 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + with: |
| 79 | + tag: ${{ github.ref_name }} |
| 80 | + body: | |
| 81 | + ${{ env.commits }} |
| 82 | + draft: false |
| 83 | + prerelease: ${{ env.prerelease }} |
| 84 | + name: ${{ github.ref_name }} - ${{ env.release_type }} |
| 85 | + |
| 86 | +# - name: Create release |
| 87 | +# uses: actions/create-release@v1 |
| 88 | +# env: |
| 89 | +# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 90 | +# with: |
| 91 | +# tag_name: ${{ github.ref_name }} |
| 92 | +# release_name: ${{ github.ref_name }} - ${{ env.release_type }} |
| 93 | +# body: | |
| 94 | +# ${{ env.commits }} |
| 95 | +# draft: false |
| 96 | +# prerelease: ${{ env.prerelease }} |
0 commit comments