Skip to content

Merge production deployment #230

Merge production deployment

Merge production deployment #230

# Make sure `Settings > Actions > General > Workflow permissions > Read and write permissions` and `Allow GitHub Actions to create and approve pull requests` are enabled
name: Merge production deployment
on:
schedule:
- cron: "0 8 * * *" # 8am UTC
workflow_dispatch:
jobs:
merge_pull_request:
runs-on: ubuntu-22.04
# Related
# - https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
# - https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps
permissions:
contents: write # Required to merge a pull request
steps:
- uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# Related:
# - https://octokit.github.io/rest.js
# - https://docs.github.com/en/rest/pulls/pulls
script: |
console.info("Fetching existing pull requests")
const existingPullRequests = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: "develop",
base: "main",
state: "open",
})
if (existingPullRequests.data.length <= 0) {
console.info(`No pull request found`)
return
}
const pullRequest = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: existingPullRequests.data[0].number,
})
// https://github.com/orgs/community/discussions/24504
// https://github.com/octokit/octokit.net/issues/1763
if (pullRequest.data.mergeable_state !== "clean") {
throw new Error(`Pull request is not mergeable: ${pullRequest.data.mergeable_state}`)
}
console.info(`Merging pull request: ${pullRequest.data.html_url}`)
try {
const mergedPullRequest = await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.data.number,
merge_method: "merge",
})
console.info(`Pull request merged`)
} catch (error) {
throw error
}