Skip to content

trigger

trigger #61

name: Auto Changelog PR
on:
release:
types: [published]
workflow_dispatch:
push:
branches:
- dlm/update-autochangelog-action
jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout the Beta9 repo
uses: actions/checkout@v3
- name: Fetch the latest release data
id: release
uses: actions/github-script@v7
with:
script: |
function formatDate(dateString) {
const date = new Date(dateString);
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const year = String(date.getFullYear()).slice(-2);
return `${month}-${day}-${year}`;
}
function prettyDate(dateString) {
const date = new Date(dateString);
return new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
timeZone: 'UTC',
}).format(date);
}
// const release = context.payload.release;
const release = {
assets: [],
assets_url: 'https://api.github.com/repos/beam-cloud/beta9/releases/178751163/assets',
author: {
avatar_url: 'https://avatars.githubusercontent.com/u/4001122?v=4',
events_url: 'https://api.github.com/users/nickpetrovic/events{/privacy}',
followers_url: 'https://api.github.com/users/nickpetrovic/followers',
following_url: 'https://api.github.com/users/nickpetrovic/following{/other_user}',
gists_url: 'https://api.github.com/users/nickpetrovic/gists{/gist_id}',
gravatar_id: '',
html_url: 'https://github.com/nickpetrovic',
id: 4001122,
login: 'nickpetrovic',
node_id: 'MDQ6VXNlcjQwMDExMjI=',
organizations_url: 'https://api.github.com/users/nickpetrovic/orgs',
received_events_url: 'https://api.github.com/users/nickpetrovic/received_events',
repos_url: 'https://api.github.com/users/nickpetrovic/repos',
site_admin: false,
starred_url: 'https://api.github.com/users/nickpetrovic/starred{/owner}{/repo}',
subscriptions_url: 'https://api.github.com/users/nickpetrovic/subscriptions',
type: 'User',
url: 'https://api.github.com/users/nickpetrovic'
},
body: "## What's Changed\r\n" +
'* Remove condition and add temporary log by @dleviminzi in https://github.com/beam-cloud/beta9/pull/592\r\n' +
'* Fix: nil okderowiahdohiawhdoieference error in eventbus by @nickpetrovic in https://github.com/beam-cloud/beta9/pull/593\r\n' +
'* Fix: ohohouiho in https://github.com/beam-cloud/beta9/pull/593\r\n' +
'\r\n' +
'\r\n' +
'**Full Changelog**: https://github.com/beam-cloud/beta9/compare/gateway-0.1.221...gateway-0.1.222',
created_at: '2024-10-07T18:28:30Z',
draft: false,
html_url: 'https://github.com/beam-cloud/beta9/releases/tag/gateway-0.1.222',
id: 178751163,
mentions_count: 2,
name: 'Gateway: 0.1.222',
node_id: 'RE_kwDOKtkjw84Kp4a7',
prerelease: false,
published_at: '2024-10-07T18:29:06Z',
tag_name: 'gateway-0.1.222',
tarball_url: 'https://api.github.com/repos/beam-cloud/beta9/tarball/gateway-0.1.222',
target_commitish: 'main',
upload_url: 'https://uploads.github.com/repos/beam-cloud/beta9/releases/178751163/assets{?name,label}',
url: 'https://api.github.com/repos/beam-cloud/beta9/releases/178751163',
zipball_url: 'https://api.github.com/repos/beam-cloud/beta9/zipball/gateway-0.1.222'
}
const lines = release.body.split('\n');
const feats = [];
const fixes = [];
for (const line of lines) {
if (line.startsWith('*')) {
const m = line.match(/^\*\s*([fF]eat|[fF]ix):\s*(.*)\s*/);
if (m) {
const [_, type, description] = m;
const byIndex = description.indexOf('by');
if (type.toLowerCase() === 'feat') {
const cleanedDesc = description.slice(0, byIndex).trim();
feats.push(cleanedDesc);
} else if (type.toLowerCase() === 'fix') {
const cleanedDesc = description.slice(0, byIndex).trim();
fixes.push(cleanedDesc);
}
}
}
}
// Stop the workflow if no features or fixes are found
if (feats.length === 0 && fixes.length === 0) {
core.setOutput('should_continue', 'false');
core.setOutput('error_message', 'No features or fixes found in the release notes. Stopping workflow.');
return;
}
const featsString = feats.map(feat => `- ${feat}`).join('\n');
const fixesString = fixes.map(fix => `- fix ${fix}`).join('\n');
core.setOutput('name', release.name.replace(/(:\s)/g, '-v'));
core.setOutput('feats', featsString);
core.setOutput('fixes', fixesString);
core.setOutput('created_at', formatDate(release.created_at));
core.setOutput('pretty_date', prettyDate(release.created_at));
core.setOutput('should_continue', 'true');
- name: Checkout beam-docs repo
if: steps.release.outputs.should_continue == 'true'
uses: actions/checkout@v3
with:
repository: slai-labs/beam-docs
path: beam-docs
token: ${{ secrets.BEAM_DOCS_PAT }}
- name: Create new release file in beam-docs
if: steps.release.outputs.should_continue == 'true'
run: |
cd beam-docs/v2/releases
FILENAME="./${{ steps.release.outputs.created_at }}.mdx"
if [ ! -f "$FILENAME" ]; then
echo "---" >> $FILENAME
echo "title: \"${{ steps.release.outputs.pretty_date }}\"" >> $FILENAME
echo "---" >> $FILENAME
echo "" >> $FILENAME
echo "## Features" >> $FILENAME
echo "${{ steps.release.outputs.feats }}" >> $FILENAME
echo "" >> $FILENAME
echo "## Fixes" >> $FILENAME
echo "${{ steps.release.outputs.fixes }}" >> $FILENAME
echo "" >> $FILENAME
else
awk -v feats="${{ steps.release.outputs.feats }}" -v fixes="${{ steps.release.outputs.fixes }}" '
/^## Features/ { print; print feats; next }
/^## Fixes/ { print; print fixes; next }
{ print }
' "$FILENAME" > "${FILENAME}.tmp" && mv "${FILENAME}.tmp" "$FILENAME"
fi
- name: Update mint.json
if: steps.release.outputs.should_continue == 'true'
run: |
cd beam-docs
NEW_FILE="v2/releases/${{ steps.release.outputs.created_at }}"
jq --arg new_file "$NEW_FILE" '
.navigation[] |=
if .group == "Releases" then
.pages |= if index($new_file) then . else [$new_file] + . end
else
.
end
' ./mint.json > ./mint.json.tmp && mv ./mint.json.tmp ./mint.json
- name: Commit and push changes
if: steps.release.outputs.should_continue == 'true'
run: |
cd beam-docs
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git checkout -b autochangelog/${{ steps.release.outputs.name }}
git add .
git commit -m "Add changelog for ${{ steps.release.outputs.name }}"
git push -u origin autochangelog/${{ steps.release.outputs.name }}
- name: Create pull request
if: steps.release.outputs.should_continue == 'true'
env:
GH_TOKEN: ${{ secrets.BEAM_DOCS_PAT }}
run: |
cd beam-docs
gh pr create --title "Changelog for ${{ steps.release.outputs.name }}" --body "This PR adds the changelog for ${{ steps.release.outputs.name }}." --base main --head autochangelog/${{ steps.release.outputs.name }}