|
| 1 | +name: Prepare release |
| 2 | + |
| 3 | +env: |
| 4 | + GIT_AUTHOR_EMAIL: "[email protected]" |
| 5 | + GIT_AUTHOR_NAME: "ci.datadog-api-spec" |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + tag: |
| 11 | + description: New version tag |
| 12 | + required: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + prepare_release: |
| 16 | + name: Create release PR |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Get GitHub App token |
| 20 | + id: get_token |
| 21 | + uses: tibdex/github-app-token@v1 |
| 22 | + with: |
| 23 | + app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }} |
| 24 | + private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }} |
| 25 | + - uses: actions/checkout@v2 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + token: ${{ steps.get_token.outputs.token }} |
| 29 | + |
| 30 | + - name: Setup Git |
| 31 | + run: | |
| 32 | + git config user.name "${GIT_AUTHOR_NAME}" |
| 33 | + git config user.email "${GIT_AUTHOR_EMAIL}" |
| 34 | +
|
| 35 | + - name: Set up Node |
| 36 | + uses: actions/setup-node@v2 |
| 37 | + with: |
| 38 | + node-version: 14 |
| 39 | + |
| 40 | + - name: Bump Gem version |
| 41 | + run: | |
| 42 | + git switch -c "release/${RELEASE_TAG}" |
| 43 | + npm version --allow-same-version --no-git-tag-version "${RELEASE_TAG#v}" |
| 44 | + git commit -a -m "Bump version to ${RELEASE_TAG}" |
| 45 | + git push -f --set-upstream origin "release/${RELEASE_TAG}" |
| 46 | + env: |
| 47 | + RELEASE_TAG: ${{ github.event.inputs.tag }} |
| 48 | + |
| 49 | + - name: Create PR |
| 50 | + uses: actions/github-script@v5 |
| 51 | + env: |
| 52 | + RELEASE_TAG: ${{ github.event.inputs.tag }} |
| 53 | + BASE: ${{ github.event.ref }} |
| 54 | + with: |
| 55 | + github-token: ${{ steps.get_token.outputs.token }} |
| 56 | + script: | |
| 57 | + const { data: notes } = await github.rest.repos.generateReleaseNotes({ |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + tag_name: process.env.RELEASE_TAG, |
| 61 | + }); |
| 62 | + const today = new Date().toJSON().slice(0, 10); |
| 63 | + const header = [`# CHANGELOG\n\n## ${process.env.RELEASE_TAG.replace(/^v/, '')} / ${today}\n`]; |
| 64 | + const changes = header.concat(notes.body.split("\n").slice(3)); |
| 65 | + const { data: content } = await github.rest.repos.getContent({ |
| 66 | + owner: context.repo.owner, |
| 67 | + repo: context.repo.repo, |
| 68 | + path: "CHANGELOG.md", |
| 69 | + }); |
| 70 | + const rawContent = Buffer.from(content.content, "base64") |
| 71 | + .toString("utf-8") |
| 72 | + .split("\n"); |
| 73 | + const newContent = changes.concat(rawContent.slice(1)).join("\n"); |
| 74 | + const { data: head } = await github.rest.git.getRef({ |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: context.repo.repo, |
| 77 | + ref: `heads/release/${process.env.RELEASE_TAG}`, |
| 78 | + }); |
| 79 | + const { data: commit } = await github.rest.repos.createOrUpdateFileContents({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + message: "Update CHANGELOG", |
| 83 | + content: Buffer.from(newContent).toString("base64"), |
| 84 | + path: "CHANGELOG.md", |
| 85 | + branch: `release/${process.env.RELEASE_TAG}`, |
| 86 | + sha: content.sha, |
| 87 | + }); |
| 88 | + const { data: pr } = await github.rest.pulls.create({ |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + head: `release/${process.env.RELEASE_TAG}`, |
| 92 | + base: process.env.BASE, |
| 93 | + title: `Release ${process.env.RELEASE_TAG}`, |
| 94 | + body: "Update CHANGELOG", |
| 95 | + }); |
| 96 | + await github.rest.issues.addLabels({ |
| 97 | + issue_number: pr.number, |
| 98 | + owner: context.repo.owner, |
| 99 | + repo: context.repo.repo, |
| 100 | + labels: ["changelog/no-changelog"], |
| 101 | + }); |
0 commit comments