|
| 1 | +--- |
| 2 | +name: "create changelog" |
| 3 | + |
| 4 | +on: |
| 5 | + issue_comment: |
| 6 | + types: [created] |
| 7 | + |
| 8 | +permissions: |
| 9 | + pull-requests: write |
| 10 | + contents: write |
| 11 | + packages: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + create-changelog: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + if: ${{ startsWith(github.event.comment.body, '/changie') && github.event.issue.pull_request }} |
| 17 | + steps: |
| 18 | + - name: Like comment |
| 19 | + uses: actions/github-script@v7 |
| 20 | + with: |
| 21 | + script: | |
| 22 | + const {owner, repo} = context.issue |
| 23 | + github.rest.reactions.createForIssueComment({ |
| 24 | + owner, |
| 25 | + repo, |
| 26 | + comment_id: context.payload.comment.id, |
| 27 | + content: "+1", |
| 28 | + }); |
| 29 | +
|
| 30 | + - uses: actions/github-script@v7 |
| 31 | + id: get-pr |
| 32 | + with: |
| 33 | + script: | |
| 34 | + const request = { |
| 35 | + owner: context.repo.owner, |
| 36 | + repo: context.repo.repo, |
| 37 | + pull_number: context.issue.number |
| 38 | + } |
| 39 | + core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`) |
| 40 | + try { |
| 41 | + const result = await github.rest.pulls.get(request) |
| 42 | + return result.data |
| 43 | + } catch (err) { |
| 44 | + core.setFailed(`Request failed with error ${err}`) |
| 45 | + } |
| 46 | +
|
| 47 | + - name: Setup outputs |
| 48 | + id: setup |
| 49 | + run: | |
| 50 | + KIND=$(echo $COMMENT | cut -d " " -f2) |
| 51 | + BODY=$(echo $COMMENT | cut -d " " -f3-) |
| 52 | + echo "Creating change of kind: $KIND and body: $BODY" |
| 53 | + echo "kind=$KIND" >> $GITHUB_OUTPUT |
| 54 | + echo "body=$BODY" >> $GITHUB_OUTPUT |
| 55 | + env: |
| 56 | + COMMENT: ${{ github.event.comment.body }} |
| 57 | + |
| 58 | + - uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + persist-credentials: false |
| 61 | + fetch-depth: 0 |
| 62 | + ref: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }} |
| 63 | + |
| 64 | + - name: Configure git repository |
| 65 | + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 66 | + |
| 67 | + - name: New changie changes |
| 68 | + uses: miniscruff/[email protected] |
| 69 | + with: |
| 70 | + version: latest |
| 71 | + args: > |
| 72 | + new |
| 73 | + --kind="${{env.KIND}}" |
| 74 | + --body="${{env.BODY}}" |
| 75 | + --custom Issue="${{env.ISSUE}}" |
| 76 | + env: |
| 77 | + KIND: ${{ steps.setup.outputs.kind }} |
| 78 | + BODY: ${{ steps.setup.outputs.body }} |
| 79 | + ISSUE: ${{ github.event.issue.number }} |
| 80 | + |
| 81 | + - name: Commit changes |
| 82 | + run: | |
| 83 | + git config --local user.email "${{ github.actor }}@users.noreply.github.com" |
| 84 | + git config --local user.name "${{ github.actor }}" |
| 85 | + git add .changes/unreleased |
| 86 | + git commit -m '${{ steps.setup.outputs.body }}' |
| 87 | + - uses: actions/create-github-app-token@v2 |
| 88 | + id: app-token |
| 89 | + with: |
| 90 | + app-id: ${{ vars.ACTIONS_APP_ID }} |
| 91 | + private-key: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }} |
| 92 | + owner: ${{ github.repository_owner }} |
| 93 | + - name: Push changes |
| 94 | + |
| 95 | + with: |
| 96 | + github_token: ${{ steps.app-token.outputs.token }} |
| 97 | + branch: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }} |
0 commit comments