Skip to content

Create production deployment #226

Create production deployment

Create production deployment #226

# Make sure `Settings > Actions > General > Workflow permissions > Read and write permissions` and `Allow GitHub Actions to create and approve pull requests` are enabled
name: Create production deployment
on:
schedule:
- cron: "30 7 * * *" # 7:30am UTC
workflow_dispatch:
jobs:
create_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:
pull-requests: write # Required for creating a pull request
steps:
- uses: actions/github-script@v7.0.1
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(`Pull request already exists: ${existingPullRequests.data[0].html_url}`)
return
}
console.info("Creating pull request")
try {
const createdPullRequest = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: "develop",
base: "main",
title: "Production deployment",
body: "**Only merge using a merge commit!**"
})
console.info(`Pull request created: ${createdPullRequest.html_url}`)
} catch (error) {
if (error.response.data.errors[0].message === "No commits between main and develop") {
console.info("No commits between main and develop")
return
}
throw error
}