Skip to content

Commit

Permalink
Add workflow to automatically create a PR from beta to stable
Browse files Browse the repository at this point in the history
This PR automatically includes changelog entries from all beta releases
since the last stable release and has the version of the latest
betarelease as title.
  • Loading branch information
tmolitor-stud-tu committed Aug 1, 2024
1 parent a526b62 commit e41e6ff
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions .github/workflows/create-stable-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Create Pull Request from Beta to Stable

on:
push:
branches: [ beta ]
workflow_dispatch:

jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Checkout Beta Branch
uses: actions/checkout@v4
with:
clean: true
submodules: true
fetch-depth: 100
fetch-tags: true
show-progress: true
lfs: true
ref: beta
- name: Checkout Stable Branch
run: |
git fetch --all
git checkout stable
git branch
- name: Get Merge Commits from Beta not in Stable
id: get_commits
run: |
function repairNotes {
sed 's/\r//g' | awk '{
if (NR == 1) {
printf("%s", $0)
} else {
if ($0 ~ /^[\t ]*(-|IOS_ONLY[\t ]*-|MACOS_ONLY[\t ]*-).*$/) {
printf("\n%s", $0)
} else {
printf(" %s", $0)
}
}
}
END {
printf("\n")
}'
}
echo "Extracting merge commit texts..."
version="$(git log beta -n 1 --merges --pretty=format:%s | sed -E 's/^[\t\n ]*([^\n\t ]+)[\t\n ]+\(([^\n\t ]+)\)[\t\n ]*$/\1/g')"
echo "version=$version" | tee /dev/stderr >> "$GITHUB_OUTPUT"
echo "buildVersion=$(echo "$version" | grep -oE '^[0-9]+(\.[0-9]+){0,2}')" | tee /dev/stderr >> "$GITHUB_OUTPUT"
echo "description<<__EOF__" | tee /dev/stderr >> "$GITHUB_OUTPUT"
echo "$(git log stable..beta --merges --pretty=format:%b)" | repairNotes | tee /dev/stderr >> "$GITHUB_OUTPUT"
echo "__EOF__" | tee /dev/stderr >> "$GITHUB_OUTPUT"
- name: Find Existing Pull Request
id: find_pr
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const { data: pullRequests } = await github.rest.pulls.list({
owner,
repo,
state: 'open',
head: 'beta',
base: 'stable'
});
const existingPR = pullRequests.find(pr => pr.labels.some(label => label.name === 'automated-pr'));
console.log(`Existing PR: `, existingPR);
if(existingPR)
return existingPR.number;
else
return null;
- name: Create or Update Pull Request
id: create_or_update_pr
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const prNumber = ${{ steps.find_pr.outputs.result }};
let pullRequest;
if(prNumber)
{
console.log(`Updating old PR #${prNumber}...`);
pullRequest = await github.rest.pulls.update({
owner,
repo,
pull_number: prNumber,
title: `${{ steps.get_commits.outputs.buildVersion }}`,
body: `${{ steps.get_commits.outputs.description }}`,
});
console.log(`Updated pull request #${prNumber}`);
}
else
{
console.log(`Creating new PR...`);
pullRequest = await github.rest.pulls.create({
owner,
repo,
head: 'beta',
base: 'stable',
draft: true,
title: `${{ steps.get_commits.outputs.buildVersion }}`,
body: `${{ steps.get_commits.outputs.description }}`,
});
console.log(`Created pull request #${pullRequest.data.number}`);
}
return pullRequest.data.number;
- name: Add Label to Pull Request
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const pullNumber = ${{ steps.create_or_update_pr.outputs.result }};
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pullNumber,
labels: ['automated-pr']
});
console.log(`Added label to pull request #${pullNumber}`);

0 comments on commit e41e6ff

Please sign in to comment.