|
| 1 | +name: Auto Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [develop] |
| 6 | + types: [opened, synchronize, reopened, closed] |
| 7 | + paths: |
| 8 | + - "package.json" |
| 9 | + issue_comment: |
| 10 | + types: [edited] |
| 11 | + |
| 12 | +jobs: |
| 13 | + generator: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: > |
| 16 | + github.event_name == 'pull_request' && |
| 17 | + github.event.pull_request.merged == false && |
| 18 | + startsWith(github.head_ref, 'release/') |
| 19 | + steps: |
| 20 | + - run: echo "The head of this PR starts with 'release/'" |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + - uses: 94dreamer/auto-release@develop |
| 23 | + id: changelog |
| 24 | + env: |
| 25 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + - name: Add comment |
| 27 | + uses: peter-evans/create-or-update-comment@v1 |
| 28 | + with: |
| 29 | + issue-number: ${{ github.event.pull_request.number }} |
| 30 | + body: | |
| 31 | + ${{ steps.changelog.outputs.changelog }} |
| 32 | + comment_add_log: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + if: > |
| 35 | + github.event_name == 'issue_comment' |
| 36 | + && github.event.issue.pull_request |
| 37 | + && github.event.sender.login == github.event.issue.user.login |
| 38 | + && startsWith(github.event.comment.body, '### 🌈 ') |
| 39 | + steps: |
| 40 | + - id: comment |
| 41 | + shell: bash |
| 42 | + run: | |
| 43 | + result=$(curl ${{github.event.issue.pull_request.url}} -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}") |
| 44 | + headrefreg='"ref": "(release/[[:digit:]]{1,2}\.[[:digit:]]{1,2}\.[[:digit:]]{1,2})",' |
| 45 | + if [[ $result =~ $headrefreg ]] |
| 46 | + then |
| 47 | + echo "属于 release pr 的 comment ${BASH_REMATCH[1]}" |
| 48 | + else |
| 49 | + echo "不属于 release pr 的 comment" && exit 1 |
| 50 | + fi |
| 51 | + echo "::set-output name=branch::${BASH_REMATCH[1]}" |
| 52 | + # zsh $match[1] |
| 53 | + - uses: actions/checkout@v3 |
| 54 | + with: |
| 55 | + ref: ${{ steps.comment.outputs.branch }} |
| 56 | + - run: echo '${{ github.event.comment.body }}' |
| 57 | + - name: Commit and push if needed |
| 58 | + run: | |
| 59 | + echo "$(echo '${{ github.event.comment.body }}' | cat - CHANGELOG.md)" > CHANGELOG.md |
| 60 | + git add . |
| 61 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 62 | + git config --local user.name "github-actions[bot]" |
| 63 | + git commit -m "chore: changelog's changes" |
| 64 | + git push |
| 65 | + echo "💾 pushed changelog's changes" |
| 66 | + merge_tag: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + if: > |
| 69 | + github.event_name == 'pull_request' && |
| 70 | + github.event.pull_request.merged == true && |
| 71 | + startsWith(github.head_ref, 'release/') |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v3 |
| 74 | + with: |
| 75 | + ref: develop |
| 76 | + - name: tag and push if needed |
| 77 | + run: | |
| 78 | + data=$(cat package.json) |
| 79 | + re="\"version\": \"([^\"]*)\"" |
| 80 | + [[ $data =~ $re ]] |
| 81 | + echo "${BASH_REMATCH[1]}" |
| 82 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 83 | + git config --local user.name "github-actions[bot]" |
| 84 | + git tag ${BASH_REMATCH[1]} |
| 85 | + git push origin ${BASH_REMATCH[1]} |
| 86 | + echo "pushed tag ${BASH_REMATCH[1]}" |
0 commit comments