From 6a63f8a915a06923fd0b493c6cad00e5f5b1bf34 Mon Sep 17 00:00:00 2001 From: wwwDayDream <13383838+wwwDayDream@users.noreply.github.com> Date: Sat, 8 Jun 2024 16:45:17 -0500 Subject: [PATCH 1/9] Change to on comment only --- .github/workflows/auto-pr-changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-pr-changelog b/.github/workflows/auto-pr-changelog index d7fb322..fb6413b 100644 --- a/.github/workflows/auto-pr-changelog +++ b/.github/workflows/auto-pr-changelog @@ -1,7 +1,7 @@ name: "[Automatic] PR Changelog" on: - pull_request_review_comment: + issue_comment: types: [created] jobs: @@ -13,4 +13,5 @@ jobs: with: script: | console.log('${{ github.event_name }}'); + console.log('${{ toJson(github.issue_comment) }}'); console.log('${{ toJson(github.event) }}'); \ No newline at end of file From 7954ea3d8a62edebd0f975536380228fcfb429ca Mon Sep 17 00:00:00 2001 From: wwwDayDream <13383838+wwwDayDream@users.noreply.github.com> Date: Sat, 8 Jun 2024 16:53:24 -0500 Subject: [PATCH 2/9] Included more branches --- .github/workflows/auto-pr-changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/auto-pr-changelog b/.github/workflows/auto-pr-changelog index fb6413b..a429505 100644 --- a/.github/workflows/auto-pr-changelog +++ b/.github/workflows/auto-pr-changelog @@ -3,6 +3,8 @@ name: "[Automatic] PR Changelog" on: issue_comment: types: [created] + branches: + - '**' jobs: auto-changelog: From 385181224fd15583cf02758022c81d849bb1af06 Mon Sep 17 00:00:00 2001 From: wwwDayDream <13383838+wwwDayDream@users.noreply.github.com> Date: Sat, 8 Jun 2024 17:09:10 -0500 Subject: [PATCH 3/9] Actually name it yml.... --- .github/workflows/auto-pr-changelog | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .github/workflows/auto-pr-changelog diff --git a/.github/workflows/auto-pr-changelog b/.github/workflows/auto-pr-changelog deleted file mode 100644 index a429505..0000000 --- a/.github/workflows/auto-pr-changelog +++ /dev/null @@ -1,19 +0,0 @@ -name: "[Automatic] PR Changelog" - -on: - issue_comment: - types: [created] - branches: - - '**' - -jobs: - auto-changelog: - runs-on: ubuntu-latest - steps: - - name: Script Execution - uses: actions/github-script@v7 - with: - script: | - console.log('${{ github.event_name }}'); - console.log('${{ toJson(github.issue_comment) }}'); - console.log('${{ toJson(github.event) }}'); \ No newline at end of file From a999f7f32a4f96880faae406ff38bfba3a5a2b2f Mon Sep 17 00:00:00 2001 From: wwwDayDream <13383838+wwwDayDream@users.noreply.github.com> Date: Sat, 8 Jun 2024 17:13:36 -0500 Subject: [PATCH 4/9] Actually add it! --- .github/workflows/auto-pr-changelog.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/auto-pr-changelog.yml diff --git a/.github/workflows/auto-pr-changelog.yml b/.github/workflows/auto-pr-changelog.yml new file mode 100644 index 0000000..fb6413b --- /dev/null +++ b/.github/workflows/auto-pr-changelog.yml @@ -0,0 +1,17 @@ +name: "[Automatic] PR Changelog" + +on: + issue_comment: + types: [created] + +jobs: + auto-changelog: + runs-on: ubuntu-latest + steps: + - name: Script Execution + uses: actions/github-script@v7 + with: + script: | + console.log('${{ github.event_name }}'); + console.log('${{ toJson(github.issue_comment) }}'); + console.log('${{ toJson(github.event) }}'); \ No newline at end of file From d76d2cb9dc86d45bfc326b72e6474fbf07560317 Mon Sep 17 00:00:00 2001 From: Day <13383838+wwwDayDream@users.noreply.github.com> Date: Sat, 8 Jun 2024 18:56:45 -0500 Subject: [PATCH 5/9] Stringify the context (#153) --- .github/workflows/auto-pr-changelog.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/auto-pr-changelog.yml b/.github/workflows/auto-pr-changelog.yml index fb6413b..931e4a5 100644 --- a/.github/workflows/auto-pr-changelog.yml +++ b/.github/workflows/auto-pr-changelog.yml @@ -12,6 +12,4 @@ jobs: uses: actions/github-script@v7 with: script: | - console.log('${{ github.event_name }}'); - console.log('${{ toJson(github.issue_comment) }}'); - console.log('${{ toJson(github.event) }}'); \ No newline at end of file + console.log(JSON.stringify(context)); \ No newline at end of file From cec809785edbb42ef0fa039de28add0652de9cff Mon Sep 17 00:00:00 2001 From: Day <13383838+wwwDayDream@users.noreply.github.com> Date: Sat, 8 Jun 2024 21:59:47 -0500 Subject: [PATCH 6/9] Auto Changelog Substance (#159) * Working theory * Updated quotes * Fixed some formatting and enabled issue comment --- .github/workflows/auto-pr-changelog.yml | 46 ++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto-pr-changelog.yml b/.github/workflows/auto-pr-changelog.yml index 931e4a5..a044409 100644 --- a/.github/workflows/auto-pr-changelog.yml +++ b/.github/workflows/auto-pr-changelog.yml @@ -1,15 +1,51 @@ -name: "[Automatic] PR Changelog" +name: "Auto Changelog" on: + pull_request: + types: [opened] issue_comment: types: [created] jobs: + set-wait-status: + name: Require Engagement + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set Wait Status + id: wait-status + uses: LouisBrunner/checks-action@v2.0.0 + with: + token: ${{ github.token }} + name: Engagement + status: 'in_progress' + output: '{ "title": "Engagement", "summary": "Prevents merging until changelog is omitted or included via `(-/+)changelog` as a comment.", "text_description": "Include or omit changelog via a `(-/+)changelog` comment." }' + + - name: Save CheckID + run: | + echo "STATUS_CHECKID=${{ steps.wait-status.outputs.check_id }}" >> "$GITHUB_STATE" + echo '${{ env.STATE_STATUS_CHECKID }}' + auto-changelog: + if: ${{ github.event_name == 'issue_comment' }} + env: + COMMENT_BODY: ${{ github.event.comment.body }} runs-on: ubuntu-latest steps: - - name: Script Execution - uses: actions/github-script@v7 + - uses: actions/checkout@v4 + + - run: | + echo '$STATE_STATUS_CHECKID' + echo '${{ env.STATE_STATUS_CHECKID }}' + + - name: Set Wait Status + id: wait-status + uses: LouisBrunner/checks-action@v2.0.0 with: - script: | - console.log(JSON.stringify(context)); \ No newline at end of file + token: ${{ github.token }} + name: Changelog Agknowledgement + status: 'completed' + conclusion: 'success' + check_id: ${{ env.STATE_STATUS_CHECKID }} \ No newline at end of file From 5e22bad668d823a9dce6e6caaf159eb28bb244e2 Mon Sep 17 00:00:00 2001 From: Day <13383838+wwwDayDream@users.noreply.github.com> Date: Sat, 8 Jun 2024 22:28:14 -0500 Subject: [PATCH 7/9] Prelogging (#162) --- .github/workflows/auto-pr-changelog.yml | 42 ++++--------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/.github/workflows/auto-pr-changelog.yml b/.github/workflows/auto-pr-changelog.yml index a044409..fe9c51b 100644 --- a/.github/workflows/auto-pr-changelog.yml +++ b/.github/workflows/auto-pr-changelog.yml @@ -1,51 +1,21 @@ name: "Auto Changelog" on: - pull_request: - types: [opened] issue_comment: types: [created] jobs: - set-wait-status: - name: Require Engagement - if: ${{ github.event_name == 'pull_request' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set Wait Status - id: wait-status - uses: LouisBrunner/checks-action@v2.0.0 - with: - token: ${{ github.token }} - name: Engagement - status: 'in_progress' - output: '{ "title": "Engagement", "summary": "Prevents merging until changelog is omitted or included via `(-/+)changelog` as a comment.", "text_description": "Include or omit changelog via a `(-/+)changelog` comment." }' - - - name: Save CheckID - run: | - echo "STATUS_CHECKID=${{ steps.wait-status.outputs.check_id }}" >> "$GITHUB_STATE" - echo '${{ env.STATE_STATUS_CHECKID }}' - auto-changelog: - if: ${{ github.event_name == 'issue_comment' }} env: COMMENT_BODY: ${{ github.event.comment.body }} + if: ${{ (contains(github.event.comment.body, '+changelog') || contains(github.event.comment.body, '-changelog')) && github.event.comment.user.login == github.event.issue.user.login }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + filter: tree:0 - run: | - echo '$STATE_STATUS_CHECKID' - echo '${{ env.STATE_STATUS_CHECKID }}' - - - name: Set Wait Status - id: wait-status - uses: LouisBrunner/checks-action@v2.0.0 - with: - token: ${{ github.token }} - name: Changelog Agknowledgement - status: 'completed' - conclusion: 'success' - check_id: ${{ env.STATE_STATUS_CHECKID }} \ No newline at end of file + echo '${{ github.head_ref }}' + echo '${{ github.ref_name }}' \ No newline at end of file From c5fce876a6e0d7736fd2cd47afec5ef4c968c485 Mon Sep 17 00:00:00 2001 From: Day <13383838+wwwDayDream@users.noreply.github.com> Date: Sat, 8 Jun 2024 23:01:45 -0500 Subject: [PATCH 8/9] Some real crimes (#164) * Prelogging * Updated crimes --- .github/workflows/auto-pr-changelog.yml | 194 +++++++++++++++++++++++- 1 file changed, 192 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-pr-changelog.yml b/.github/workflows/auto-pr-changelog.yml index fe9c51b..64c3411 100644 --- a/.github/workflows/auto-pr-changelog.yml +++ b/.github/workflows/auto-pr-changelog.yml @@ -16,6 +16,196 @@ jobs: fetch-depth: 0 filter: tree:0 + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_SIGNING_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + + - name: Reset Changelog + continue-on-error: true + run: | + git checkout ${{ github.ref_name }} -- ./README.md + + - name: CHANGELOG Setup + if: ${{ contains(github.event.comment.body, '+changelog') }} + uses: actions/github-script@v7 + env: + HEAD_REF: ${{ github.head_ref }} + ISSUE_TITLE: ${{ github.event.issue.title }} + with: + script: | + const fs = require('fs'); + const filePath = 'CHANGELOG.md'; + const headRef = process.env.HEAD_REF; + + Array.prototype.insert = function ( index, ...items ) { + this.splice( index, 0, ...items ); + }; + + class MarkdownHead { + constructor(level = 0, parent = null) { + this.level = level; + this.children = []; + if (parent != null && parent.children != null) + parent.children.push(this); + } + + findOrCreateChildHead(firstLineContains, template) { + for (var idx = 0; idx < this.children.length; idx++) { + var cur = this.children[idx]; + if (typeof(cur) == typeof('') || cur.children == null) continue; + if (cur.children.length > 0 && cur.children[0].toLowerCase().includes(firstLineContains.toLowerCase())) { + return cur; + } + } + + var newHead = new MarkdownHead(this.level + 1, this); + if (template != null) + newHead.children = template.split('\n'); + else + newHead.children = [ '#'.repeat(newHead.level) + ' ' + firstLineContains ]; + return newHead; + } + + cleanup() { + while (this.children.length > 0 && typeof(this.children[this.children.length - 1]) == typeof('') && this.children[this.children.length - 1].replace(' ', '') == '') + this.children.pop(); + while (this.children.length > 0 && typeof(this.children[0]) == typeof('') && this.children[0].replace(' ', '') == '') + this.children.remove(0); + } + + parse(markdown) { + var inChild = false; + const markdownSplit = markdown.split('\n'); + const headStack = [ this ]; + for (var idx = 0; idx < markdownSplit.length; idx++) { + const currentLine = markdownSplit[idx]; + const match = currentLine.match(/^(#+).*$/) + + const matchLevel = match != null ? match[1].length : -1; + var newHead; + + // Handle all head changes + if (match && matchLevel > headStack[headStack.length - 1].level) { + newHead = new MarkdownHead(matchLevel, headStack[headStack.length - 1]); + headStack.push(newHead); + } else if (match && matchLevel == headStack[headStack.length - 1].level) { + headStack.pop().cleanup(); + newHead = new MarkdownHead(matchLevel, headStack[headStack.length - 1]); + headStack.push(newHead); + } else if (match && matchLevel < headStack[headStack.length - 1].level) { + while (matchLevel <= headStack[headStack.length - 1].level) { + headStack.pop().cleanup(); + } + newHead = new MarkdownHead(matchLevel, headStack[headStack.length - 1]); + headStack.push(newHead); + } + + const currentHead = headStack[headStack.length - 1]; + + currentHead.children.push(currentLine); + } + + this.cleanup(); + } + + toString() { + var curString = ""; + for (var idx = 0; idx < this.children.length; idx++) { + const curElem = this.children[idx]; + if (typeof(curElem) == typeof("")) + curString += `${curElem}\n`; + else { + if (curElem.children.length <= 1) + continue; // Skip empty sections + + if (curElem.children.length > 1 && curElem.children[1] != "") + curElem.children.insert(1, ""); + if (curElem.children.length > 0 && curElem.children[0] != "" && + curString.length > 0 && !curString.endsWith('\n\n')) + curElem.children.insert(0, ""); + curString += curElem.toString(); + } + } + return curString; + } + } + + const DefaultChangelog = `# Changelog + + All notable changes to this project will be documented in this file. + + The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), + and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).`; + + // Check if the file exists and read its content if it does + let fileContent = ''; + if (fs.existsSync(filePath)) { + fileContent = fs.readFileSync(filePath, 'utf8'); + } + + const masterHead = new MarkdownHead(); + masterHead.parse(fileContent); + + (() => { // + + masterHead.changelog = masterHead.findOrCreateChildHead("Changelog", DefaultChangelog); + masterHead.changelog.unreleased = masterHead.changelog.findOrCreateChildHead("[Unreleased]"); + + masterHead.changelog.unreleased.added = + masterHead.changelog.unreleased.findOrCreateChildHead("Added"); + masterHead.changelog.unreleased.changed = + masterHead.changelog.unreleased.findOrCreateChildHead("Changed"); + masterHead.changelog.unreleased.deprecated = + masterHead.changelog.unreleased.findOrCreateChildHead("Deprecated"); + masterHead.changelog.unreleased.removed = + masterHead.changelog.unreleased.findOrCreateChildHead("Removed"); + masterHead.changelog.unreleased.fixed = + masterHead.changelog.unreleased.findOrCreateChildHead("Fixed"); + masterHead.changelog.unreleased.secured = + masterHead.changelog.unreleased.findOrCreateChildHead("Secured"); + + })(); + + console.log(headRef); + var category = headRef.split('/')[0]; + var potentialHead = masterHead.changelog.unreleased[category]; + if (potentialHead != null) { + potentialHead.children.push('- ' + process.env.ISSUE_TITLE); + } + + fs.writeFileSync(filePath, masterHead.toString()); + + console.log("-=-=-=-=-\nWhat we have exported..."); + console.log(masterHead.toString()); + - run: | - echo '${{ github.head_ref }}' - echo '${{ github.ref_name }}' \ No newline at end of file + git add . + git commit -am "Updated README.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 From 58288f09492717fe845e9616cace3cb05068a6f4 Mon Sep 17 00:00:00 2001 From: Day <13383838+wwwDayDream@users.noreply.github.com> Date: Mon, 10 Jun 2024 23:57:15 -0500 Subject: [PATCH 9/9] Event that fires auto-changelog (#167) * Changed to pull request events * Additional Logging * Adjusted branches accordingly * Finalizing execution * Updated README.md * Try double checkout * Clean false * Branch tracking * Wrong reset * Wording * I've been bamboozled * Remove first * Updated CHANGELOG.md * Updated CHANGELOG.md * Do some logging * Switched over to labeling * Equals true lol * Continue on errors * Updated CHANGELOG.md * Updated CHANGELOG.md * Updated CHANGELOG.md --- .github/workflows/auto-pr-changelog.yml | 27 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto-pr-changelog.yml b/.github/workflows/auto-pr-changelog.yml index 64c3411..6cf99ff 100644 --- a/.github/workflows/auto-pr-changelog.yml +++ b/.github/workflows/auto-pr-changelog.yml @@ -1,21 +1,27 @@ name: "Auto Changelog" on: - issue_comment: - types: [created] + pull_request: + types: [labeled, unlabeled] jobs: auto-changelog: + if: ${{ github.event.label.name == 'Changelog' }} env: - COMMENT_BODY: ${{ github.event.comment.body }} - if: ${{ (contains(github.event.comment.body, '+changelog') || contains(github.event.comment.body, '-changelog')) && github.event.comment.user.login == github.event.issue.user.login }} + LABEL_ADDED: ${{ github.event.action == 'labeled' }} + PR_TITLE: ${{ github.event.pull_request.title }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: + ref: ${{ github.head_ref }} + clean: false fetch-depth: 0 filter: tree:0 + - run: | + git branch --track ${{ github.base_ref }} origin/${{ github.base_ref }} + - name: Import GPG key uses: crazy-max/ghaction-import-gpg@v6 with: @@ -27,14 +33,15 @@ jobs: - name: Reset Changelog continue-on-error: true run: | - git checkout ${{ github.ref_name }} -- ./README.md + rm CHANGELOG.md + git checkout ${{ github.base_ref }} -- CHANGELOG.md - name: CHANGELOG Setup - if: ${{ contains(github.event.comment.body, '+changelog') }} + if: ${{ env.LABEL_ADDED == 'true' }} uses: actions/github-script@v7 env: HEAD_REF: ${{ github.head_ref }} - ISSUE_TITLE: ${{ github.event.issue.title }} + ISSUE_TITLE: ${{ env.PR_TITLE }} with: script: | const fs = require('fs'); @@ -173,6 +180,7 @@ 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); } @@ -182,9 +190,10 @@ jobs: console.log("-=-=-=-=-\nWhat we have exported..."); console.log(masterHead.toString()); - - run: | + - continue-on-error: true + run: | git add . - git commit -am "Updated README.md" + git commit -am "Updated CHANGELOG.md" - name: PR Check id: pr-check