diff --git a/.github/scripts/unreleasedChanges.js b/.github/scripts/unreleasedChanges.js new file mode 100755 index 000000000..4636f1a09 --- /dev/null +++ b/.github/scripts/unreleasedChanges.js @@ -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}<> $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), + ]); +})(); diff --git a/.github/workflows/unreleaseChangesCheck.yml b/.github/workflows/unreleaseChangesCheck.yml index 1a1a432d7..4c6ea6bac 100644 --- a/.github/workflows/unreleaseChangesCheck.yml +++ b/.github/workflows/unreleaseChangesCheck.yml @@ -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 @@ -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<> $GITHUB_ENV - echo $MOST_RECENT_TAG >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - echo "LOG<> $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 @@ -37,6 +28,6 @@ jobs: notify_when: 'success' notification_title: 'Unreleased Changes in the CLI' message_format: '${{ env.LOG }}' - footer: '<{run_url}|View Run> | ' + footer: '<{run_url}|View Run> | | ' env: SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}