Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 38 additions & 41 deletions .github/workflows/auto-pr-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
clean: false
fetch-depth: 0
filter: tree:0
ref: ${{ github.event.repository.default_branch }}

- id: remote-data
run: |
git branch -a -l origin/added/changelog-entry
echo "REMOTE_EXISTS=$(git branch -a -l origin/added/changelog-entry)" >> $GITHUB_OUTPUT

- name: Create Remote Branch
if: ${{ !contains(steps.remote-data.outputs.REMOTE_EXISTS, 'remotes/origin/added/changelog-entry') }}
run: |
git branch added/changelog-entry
git push -u origin added/changelog-entry

- run: |
git branch --track ${{ github.base_ref }} origin/${{ github.base_ref }}
- continue-on-error: true
run: |
git checkout added/changelog-entry

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
Expand All @@ -32,23 +42,19 @@ jobs:
git_user_signingkey: true
git_commit_gpgsign: true

- name: Reset Changelog
continue-on-error: true
run: |
rm CHANGELOG.md
git checkout ${{ github.base_ref }} -- CHANGELOG.md

- name: CHANGELOG Setup
if: ${{ env.LABEL_ADDED == 'true' }}
uses: actions/github-script@v7
env:
HEAD_REF: ${{ github.head_ref }}
ISSUE_TITLE: ${{ env.PR_TITLE }}
ISSUE_NUMBER: ${{ github.event.pull_request.number }}
ISSUE_URL: ${{ github.event.pull_request.html_url }}
with:
script: |
const fs = require('fs');
const filePath = 'CHANGELOG.md';
const headRef = process.env.HEAD_REF;
const labelAdded = process.env.LABEL_ADDED == 'true';

Array.prototype.insert = function ( index, ...items ) {
this.splice( index, 0, ...items );
Expand Down Expand Up @@ -179,44 +185,35 @@ jobs:

})();

console.log(headRef);
var category = headRef.split('/')[0];
var potentialHead = masterHead.changelog.unreleased[category];
console.log(potentialHead);
if (potentialHead != null) {
potentialHead.children.push('- ' + process.env.ISSUE_TITLE);
var entryPRPrefix = '- [#' + process.env.ISSUE_NUMBER + '](' + process.env.ISSUE_URL + ')';
var potentialEntry = entryPRPrefix + ' ' + process.env.ISSUE_TITLE;
if (labelAdded) {
if (potentialHead != null) {
potentialHead.children.push(potentialEntry);
}
} else {
const newChildren = [];
for (var curIdx = 0; curIdx < potentialHead.children.length; curIdx++) {
const curItem = potentialHead.children[curIdx];
if (typeof(curItem) != typeof('') || !curItem.startsWith(entryPRPrefix)) {
newChildren.push(curItem);
}
}
potentialHead.children = newChildren;
}

fs.writeFileSync(filePath, masterHead.toString());
fs.writeFileSync(filePath, masterHead.toString().trim());

console.log("-=-=-=-=-\nWhat we have exported...");
console.log(masterHead.toString());
console.log(masterHead.toString().trim());

- continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
git add .
git commit -am "Updated CHANGELOG.md"

- name: PR Check
id: pr-check
uses: actions/github-script@v7
with:
script: |
const execSync = require('child_process').execSync;
const branchStatus = execSync('git status -sb').toString();
const result = branchStatus.match(/^##\s*([\w\d-_/\\]+)\.\.\.([\w\d-_/\\]+)/)
if (!result)
throw new Exception("Weird");

const currentBranch = result[1];
const trackingBranch = result[2];
const diff = execSync(`git diff ${currentBranch} ${trackingBranch}`).toString();
core.setOutput('push-needed', diff != "" ? 'true' : 'false');
console.log(currentBranch);
console.log(trackingBranch);
console.log(diff);

- name: Push Changes
if: steps.pr-check.outputs.push-needed == 'true'
run: |
git push
gh pr create --base ${{ github.event.repository.default_branch }} --head added/changelog-entry --title "Updated CHANGELOG.md" --body "" || echo "PR already exists or another error occurred"