Skip to content

Production deployment #4

Production deployment

Production deployment #4

name: Production deployment
on:
schedule:
- cron: '0 0 * * *'
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 actions/github-script
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(`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",
})
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
}