name: Prepare release env: GIT_AUTHOR_EMAIL: "packages@datadoghq.com" GIT_AUTHOR_NAME: "ci.datadog-api-spec" on: workflow_dispatch: inputs: tag: description: New version tag required: true jobs: prepare_release: name: Create release PR runs-on: ubuntu-latest steps: - name: Get GitHub App token id: get_token uses: tibdex/github-app-token@v1 with: app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }} private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }} - uses: actions/checkout@v2 with: fetch-depth: 0 token: ${{ steps.get_token.outputs.token }} - name: Setup Git run: | git config user.name "${GIT_AUTHOR_NAME}" git config user.email "${GIT_AUTHOR_EMAIL}" - name: Set up Ruby 2.6 uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 - name: Bump Gem version run: | git switch -c "release/${RELEASE_TAG}" bundle install bundle exec gem bump -v "${RELEASE_TAG#v}" git push -f --set-upstream origin "release/${RELEASE_TAG}" env: RELEASE_TAG: ${{ github.event.inputs.tag }} - name: Create PR uses: actions/github-script@v5 env: RELEASE_TAG: ${{ github.event.inputs.tag }} BASE: ${{ github.event.ref }} with: github-token: ${{ steps.get_token.outputs.token }} script: | const { data: notes } = await github.rest.repos.generateReleaseNotes({ owner: context.repo.owner, repo: context.repo.repo, tag_name: process.env.RELEASE_TAG, }); const today = new Date().toJSON().slice(0, 10); const header = [`# CHANGELOG\n\n## ${process.env.RELEASE_TAG} / ${today}\n`]; const changes = header.concat(notes.body.split("\n").slice(3)); const { data: content } = await github.rest.repos.getContent({ owner: context.repo.owner, repo: context.repo.repo, path: "CHANGELOG.md", }); const rawContent = Buffer.from(content.content, "base64") .toString("utf-8") .split("\n"); const newContent = changes.concat(rawContent.slice(1)).join("\n"); const { data: head } = await github.rest.git.getRef({ owner: context.repo.owner, repo: context.repo.repo, ref: `heads/release/${process.env.RELEASE_TAG}`, }); const { data: commit } = await github.rest.repos.createOrUpdateFileContents({ owner: context.repo.owner, repo: context.repo.repo, message: "Update CHANGELOG", content: Buffer.from(newContent).toString("base64"), path: "CHANGELOG.md", branch: `release/${process.env.RELEASE_TAG}`, sha: content.sha, }); const { data: pr } = await github.rest.pulls.create({ owner: context.repo.owner, repo: context.repo.repo, head: `release/${process.env.RELEASE_TAG}`, base: process.env.BASE, title: `Release ${process.env.RELEASE_TAG}`, body: "Update CHANGELOG", }); await github.rest.issues.addLabels({ issue_number: pr.number, owner: context.repo.owner, repo: context.repo.repo, labels: ["changelog/no-changelog"], });