Skip to content

Commit

Permalink
chore: Improve unreleased changes script (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager authored Dec 2, 2024
1 parent da37b4b commit 57524d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
43 changes: 43 additions & 0 deletions .github/scripts/unreleasedChanges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node

const { exec: _exec } = require('child_process');
const util = require('util');

const exec = util.promisify(_exec);

async function gitLogForTag(tag) {
const { stdout } = await exec(
`git log v${tag}...origin/main --pretty=format:'- %s – @%al.' --no-merges`
);
return stdout;
}

async function outputEnvVariable(name, value) {
await exec(
`echo "${name}<<EOF" >> $GITHUB_ENV && echo "${value}" >> $GITHUB_ENV && echo "EOF" >> $GITHUB_ENV`
);
}
(async () => {
const { stdout } = await exec('npm view @hubspot/cli dist-tags --json');
const { next, latest } = JSON.parse(stdout);

const logs = [
['latest', await gitLogForTag(latest)],
['next', await gitLogForTag(next)],
];

const output = logs
.map(item => {
const [tag, gitLog] = item;
return `\n ## Diff between ${tag} and main:\n${
gitLog === '' ? 'No changes' : gitLog
}`;
})
.join('\n');

await Promise.all([
outputEnvVariable('LOG', output),
outputEnvVariable('NEXT_TAG', next),
outputEnvVariable('LATEST_TAG', latest),
]);
})();
23 changes: 7 additions & 16 deletions .github/workflows/unreleaseChangesCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 18.x
- uses: actions/checkout@v4
with:
# Always checkout the main branch
Expand All @@ -14,21 +19,7 @@ jobs:
# Fetch all the release tags
fetch-tags: true
- name: Check for unreleased changes
id: get-diff-log
run: |
export MOST_RECENT_TAG=$(git describe --tags --abbrev=0);
echo $MOST_RECENT_TAG
export LOG=`git log $MOST_RECENT_TAG..main --pretty=format:'- %s – @%al.' --no-merges`
echo $LOG
echo "MOST_RECENT_TAG<<EOF" >> $GITHUB_ENV
echo $MOST_RECENT_TAG >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "LOG<<EOF" >> $GITHUB_ENV
echo "$LOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
run: node .github/scripts/unreleasedChanges.js
- name: Unreleased changes Slack Report
uses: ravsamhq/notify-slack-action@v2
if: ${{ env.LOG != '' }} # Only post if there is a log
Expand All @@ -37,6 +28,6 @@ jobs:
notify_when: 'success'
notification_title: 'Unreleased Changes in the CLI'
message_format: '${{ env.LOG }}'
footer: '<{run_url}|View Run> | <https://github.com/HubSpot/hubspot-cli/compare/${{env.MOST_RECENT_TAG}}...main|View in GitHub>'
footer: '<{run_url}|View Run> | <https://github.com/HubSpot/hubspot-cli/compare/v${{env.LATEST_TAG}}...main|View latest Diff in GitHub> | <https://github.com/HubSpot/hubspot-cli/compare/v${{env.NEXT_TAG}}...main|View next Diff in GitHub>'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}

0 comments on commit 57524d9

Please sign in to comment.