Skip to content

Create Release PR

Create Release PR #39

# This workflow automatically creates a release PR for the CI integration.
name: Create Release PR
env:
GIT_AUTHOR_EMAIL: '[email protected]'
GIT_AUTHOR_NAME: 'ci.datadog-ci'
on:
workflow_dispatch:
inputs:
semver:
description: 'Semver argument for the version bump to do on the CI integration'
default: 'minor'
type: choice
options:
- 'patch'
- 'minor'
- 'major'
jobs:
create-release-pr:
runs-on: ubuntu-latest
steps:
# Do the changes
- name: Get GitHub App token
id: get-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.RELEASE_AUTOMATION_GITHUB_APP_ID }}
private-key: ${{ secrets.RELEASE_AUTOMATION_GITHUB_APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.get-token.outputs.token }}
- name: Install node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
- name: Create release branch
run: git checkout -b local-branch
- name: Set git user
run: |
git config user.name "${GIT_AUTHOR_NAME}"
git config user.email "${GIT_AUTHOR_EMAIL}"
- name: Install dependencies
run: yarn install
- name: Bump CI integration version
id: bump-version
run: |
OLD_VERSION_TAG="v$(jq -r '.version' package.json)" # e.g. v1.0.0
# The `version` command only bumps the version in package.json. It doesn't commit nor tag.
yarn version ${{ github.event.inputs.semver }}
NEW_VERSION_TAG="v$(jq -r '.version' package.json)" # e.g. v1.1.0
# Update README with new version
sed -i "s/$OLD_VERSION_TAG/$NEW_VERSION_TAG/" README.md
echo "NEW_VERSION_TAG=$NEW_VERSION_TAG" >> $GITHUB_OUTPUT
- name: Update build files
run: |
yarn build
yarn package
- name: Commit new version
run: |
git add --all
git commit -m ${{ steps.bump-version.outputs.NEW_VERSION_TAG }}
- name: Push the branch
run: git push -u origin local-branch:release/${{ steps.bump-version.outputs.NEW_VERSION_TAG }}
# Create the pull request
- name: Generate release notes
id: generate-release-notes
uses: actions/github-script@v7
with:
github-token: ${{ steps.get-token.outputs.token }}
script: |
const { data: releaseNotes } = await github.rest.repos.generateReleaseNotes({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ steps.bump-version.outputs.NEW_VERSION_TAG }}',
})
core.setOutput('RELEASE_NOTES', releaseNotes.body)
- name: Create pull request
id: create-pull-request
uses: actions/github-script@v7
with:
github-token: ${{ steps.get-token.outputs.token }}
script: |
const { data: pullRequest } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
base: 'main',
head: 'release/${{ steps.bump-version.outputs.NEW_VERSION_TAG }}',
title: '[release:${{ github.event.inputs.semver }}] `${{ steps.bump-version.outputs.NEW_VERSION_TAG }}`',
body: ${{ toJSON(steps.generate-release-notes.outputs.RELEASE_NOTES) }}
})
core.setOutput('PULL_REQUEST_NUMBER', pullRequest.number)
- name: Create comment
uses: actions/github-script@v7
with:
github-token: ${{ steps.get-token.outputs.token }}
script: |
const body = `Once merged, this PR will automatically create a GitHub release for you.
The description of the release will exactly match this PR's description. Feel free to edit it.
> [!WARNING]
> The release will be created **but not published** on the GitHub Marketplace (because the API doesn't allow that).
>
> To publish it manually, please edit the release [here](https://github.com/DataDog/synthetics-ci-github-action/releases/edit/${{ steps.bump-version.outputs.NEW_VERSION_TAG }}).
> Make sure the \`Publish this Action to the GitHub Marketplace\` checkbox is checked, and click \`Update release\`.`
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.create-pull-request.outputs.PULL_REQUEST_NUMBER }},
body,
})