Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Do some YAML magic extraordinaire to rewrite the changelog (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
JForsaken authored Apr 1, 2022
1 parent 1b8b5c2 commit 8749e83
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
37 changes: 22 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
name: Release
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.persist_release.outputs.release_id }}
released: ${{ steps.persist_release.outputs.released }}
changelog: ${{ steps.persist_release.outputs.changelog }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -48,10 +48,28 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- id: persist_release
- name: Fetch Release
if: steps.release.outputs.released == 'true'
uses: cardinalby/git-get-release-action@v1
id: fetch_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseId: ${{ steps.release.outputs.release_id }}

- name: Output Release Changelog
if: steps.release.outputs.released == 'true'
run: echo "${{ steps.fetch_release.outputs.body }}"

- name: Persist Release
if: steps.release.outputs.released == 'true'
id: persist_release
env:
RAW_CHANGELOG: ${{ steps.fetch_release.outputs.body }}
REPO_URL: ${{ github.repositoryUrl }}
run: |
echo "::set-output name=release_id::${{ steps.release.outputs.release_id }}"
echo "::set-output name=released::${{ steps.release.outputs.released }}"
echo "::set-output name=changelog::$(node ./scripts/rewrite-changelog.js RAW_CHANGELOG $REPO_URL)"
bump_zapper_studio:
name: Bump on Zapper API
Expand All @@ -70,17 +88,6 @@ jobs:
token: ${{ secrets.GH_ZAPPER_BOT }}
ref: master

- name: Output Release ID
run: echo "Release ID ${{ needs.release.outputs.release_id }}"

- name: Fetch Release
uses: cardinalby/git-get-release-action@v1
id: fetch_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseId: ${{ needs.release.outputs.release_id }}

- name: Setup Node
uses: actions/setup-node@v2
with:
Expand Down Expand Up @@ -112,6 +119,6 @@ jobs:
body: |
⚙️ _This pull request was opened automatically from Zapper-fi/studio._
${{ steps.fetch_release.outputs.body }}
${{ needs.release.outputs.changelog }}
base: master
delete-branch: true
27 changes: 27 additions & 0 deletions scripts/rewrite-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const [envVarTarget, repoUrl] = process.argv.slice(2);

function run() {
const rawChangelog = process.env[envVarTarget];
const prSectionExpr = /.*(\(#(\d.*)\))$/;

const lines = rawChangelog.split('\n');
const rewrittenLines = lines
.map(line => {
try {
// In commit `whatever (#234)`, extract `(#234)` and `234`
const [, prSection, prNumber] = prSectionExpr.exec(line);
// Rewrite line using a URL of the pull request rather than just `(#234)`
const [lineStart] = line.split(prSection);
const rewrittenPrSection = `(${repoUrl}/pull/${prNumber})`;
return [lineStart, rewrittenPrSection].join('');
} catch (e) {
return line;
}
})
.join('\n');

/* eslint-disable-next-line no-console */
console.log(rewrittenLines);
}

run();

0 comments on commit 8749e83

Please sign in to comment.