Production deployment #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/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 | |
} |