Skip to content

release-prepare-monthly #4

release-prepare-monthly

release-prepare-monthly #4

name: release-prepare-monthly
on:
schedule:
# Runs at midnight UTC on the 1st of every month
- cron: '0 0 1 * *'
workflow_dispatch:
jobs:
create-release-pr:
runs-on: ubuntu-latest
steps:
- name: Check if running on the original repository
run: |
if [ "$GITHUB_REPOSITORY_OWNER" != "parse-community" ]; then
echo "This is a forked repository. Exiting."
exit 1
fi
- name: Checkout working branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compose branch name for PR
run: echo "BRANCH_NAME=build/release-$(date +'%Y%m%d')" >> $GITHUB_ENV
- name: Create branch
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
git checkout -b ${{ env.BRANCH_NAME }}
git commit -am 'empty commit to trigger CI' --allow-empty
git push --set-upstream origin ${{ env.BRANCH_NAME }}
- name: Create or update PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.RELEASE_GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const head = '${{ env.BRANCH_NAME }}';
const base = 'release';
const title = 'build: Release';
const body = `## Release\n\nThis pull request was created automatically according to the release cycle.\n\n> [!WARNING]\n> Only use \`Merge Commit\` to merge this pull request. Do not use \`Rebase and Merge\` or \`Squash and Merge\`.`;
// Check for existing open PR
const pulls = await github.rest.pulls.list({
owner,
repo,
head: `${owner}:${head}`,
state: 'open',
});
if (pulls.data.length > 0) {
const prNumber = pulls.data[0].number;
await github.rest.pulls.update({
owner,
repo,
pull_number: prNumber,
title,
body,
});
core.info(`Updated PR #${prNumber}`);
} else {
const pr = await github.rest.pulls.create({
owner,
repo,
title,
body,
head,
base,
});
core.info(`Created PR #${pr.data.number}`);
}