Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 67 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 60

steps:
- name: Generate bot token
Expand All @@ -52,13 +52,13 @@ jobs:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}

- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
Expand All @@ -68,6 +68,11 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Capture previous tag
if: github.ref_name == 'main'
id: previous_tag
run: echo "tag=$(git describe --tags --abbrev=0 --exclude='*-*' 2>/dev/null || true)" >> "$GITHUB_OUTPUT"

- name: Release
run: npx semantic-release
env:
Expand All @@ -76,3 +81,62 @@ jobs:
GIT_AUTHOR_EMAIL: ${{ steps.bot_user.outputs.id }}+${{ steps.generate_token.outputs.app-slug }}[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: ${{ steps.generate_token.outputs.app-slug }}[bot]
GIT_COMMITTER_EMAIL: ${{ steps.bot_user.outputs.id }}+${{ steps.generate_token.outputs.app-slug }}[bot]@users.noreply.github.com

- name: Derive release announcement
if: github.ref_name == 'main'
id: announcement
env:
PREVIOUS_TAG: ${{ steps.previous_tag.outputs.tag }}
run: |
git fetch --force --tags origin

new_tag="$(git describe --tags --abbrev=0 2>/dev/null || true)"
if [ -z "${new_tag}" ] || [ "${new_tag}" = "${PREVIOUS_TAG}" ]; then
echo "should_announce=false" >> "$GITHUB_OUTPUT"
exit 0
fi

package_name="$(node -p "JSON.parse(require('fs').readFileSync('package.json', 'utf8')).name")"
package_version="$(node -p "JSON.parse(require('fs').readFileSync('package.json', 'utf8')).version")"
release_version="${new_tag#v}"

package_url="https://www.npmjs.com/package/${package_name}/v/${package_version}"
release_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${new_tag}"
repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"

if [ -n "${PREVIOUS_TAG}" ]; then
changelog="$(git log --no-merges --reverse --pretty='format:- %s (%H-%h)' "${PREVIOUS_TAG}..${new_tag}" | grep -v '^- chore(release): ' || true)"
Comment thread
henningmu marked this conversation as resolved.
else
changelog="$(git log --no-merges --reverse --pretty='format:- %s (%H-%h)' "${new_tag}" | grep -v '^- chore(release): ' || true)"
fi

if [ -z "${changelog}" ]; then
changelog='- No additional commits listed.'
else
changelog="$(printf '%s\n' "${changelog}" | sed -E -e 's,\(([a-f0-9]+)-([a-f0-9]+)\),([`\2`]('"${repo_url}"'/commit/\1)),g' | sed -E -e 's,\(#([0-9]+)\),([#\1]('"${repo_url}"'/pull/\1)),g')"
fi

{
echo "should_announce=true"
echo "message<<EOF"
echo "**Comms CLI ${new_tag} published 🚀**"
echo
printf '%s\n' "${changelog}"
echo
echo "[GitHub release](${release_url}) | [npm package](${package_url})"
echo "EOF"
} >> "$GITHUB_OUTPUT"

- name: Announce release in Comms
if: github.ref_name == 'main' && steps.announcement.outputs.should_announce == 'true'
uses: Doist/comms-actions/post-comment-action@main
with:
comms-client-id: ${{ secrets.COMMS_CLIENT_ID }}
comms-client-secret: ${{ secrets.COMMS_CLIENT_SECRET }}
comms-username: ${{ secrets.COMMS_USERNAME }}
comms-password: ${{ secrets.COMMS_PASSWORD }}
workspace-id: 69
thread-id: CZECS4Yebwx7c1c8hDRmB
content: ${{ steps.announcement.outputs.message }}
audience: channel
continue-on-error: true
Loading