Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Jul 18, 2024
1 parent 6736f11 commit 496c856
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions .github/workflows/backfill-changelogs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,29 @@ jobs:
uses: actions/github-script@v6
with:
script: |
const response = await github.rest.repos.listReleases({
owner: 'mollie',
repo: 'mollie-api-php',
});
const releases = response.data;
releases.sort((a, b) => new Date(a.published_at) - new Date(b.published_at));
return JSON.stringify(releases.map(release => ({
async function getAllReleases(page = 1, releases = []) {
const response = await github.rest.repos.listReleases({
owner: 'mollie',
repo: 'mollie-api-php',
per_page: 100,
page: page
});
releases = releases.concat(response.data);
if (response.data.length === 100) {
return await getAllReleases(page + 1, releases);
}
return releases;
}
const allReleases = await getAllReleases();
allReleases.sort((a, b) => new Date(a.published_at) - new Date(b.published_at));
return JSON.stringify(allReleases.map(release => ({
tag_name: release.tag_name,
name: release.name,
body: release.body.replace(/\n/g, '\\n').replace(/"/g, '\\"').replace(/\*/g, '\\*'), // Replace newlines and escape quotes
body: release.body.replace(/\n/g, '\\n').replace(/"/g, '\\"'), // Replace newlines and escape quotes
published_at: release.published_at
})));
- name: Debug releases output
run: |
echo "Releases output:"
echo '${{ steps.get_releases.outputs.result }}'
- name: Update Changelog
run: |
releases='${{ steps.get_releases.outputs.result }}'
echo "Formatted releases for processing:"
echo "$releases"
changelog="# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe 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).\n\n"
echo "$releases" | jq -c '.[]' | while read -r release; do
tag_name=$(echo "$release" | jq -r '.tag_name')
name=$(echo "$release" | jq -r '.name')
body=$(echo "$release" | jq -r '.body' | sed 's/\\\\n/\\n/g') # Properly handle newlines
published_at=$(echo "$release" | jq -r '.published_at')
changelog+="## [$tag_name] - $published_at\n\n$body\n\n"
done
echo -e "$changelog" > CHANGELOG.md
- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: "Backfill CHANGELOG with past releases"
file_pattern: CHANGELOG.md

0 comments on commit 496c856

Please sign in to comment.