Skip to content

Commit

Permalink
Release helper script and CI (#452)
Browse files Browse the repository at this point in the history
* Remove container version

* Add release script

* Add

* Add npm publish script

* Remove unused id

* Testing tag publish

fix ref name

change the command

fetch depth

Try checking out the tag

Remove tag check

Releasey bits

Tag file

Try fetching

all tags

Ask it very nicely to fetch tags

needs a force to make it happy

Finally get tags working

fix fails

Simpify

Correct param

Fix name

s/file/path

Update release script

Test publish workflow

forgot to checkout

test publication

Use npm publish

Use proper publish script

* Commit the version

* Tidy up scripts

* Update release.yml

* Update release.sh

* Cleanup

* changelog
  • Loading branch information
Half-Shot authored Dec 9, 2022
1 parent 9dac938 commit a6be350
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 9 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
release:
types: [published]

jobs:
publish-to-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- run: yarn --strict-semver --frozen-lockfile
- run: yarn build
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
push:
tags: ["[0-9].[0-9].[0-9]"]

jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get changelog
id: extract-changelog
run: |
git fetch --tags --force
RELEASE_NAME="${{ github.ref_name }} $(date +'%Y-%m-%d')"
git tag -l --format='%(contents:body)' ${{ github.ref_name }} > next-changelog.txt
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
name: ${{ steps.extract-changelog.outputs.RELEASE_NAME }}
body_path: next-changelog.txt
draft: true # Draft it
token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Tests
on:
push:
workflow_dispatch:
pull_request:

jobs:
lint:
Expand All @@ -12,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
- run: yarn --strict-semver --frozen-lockfile
Expand All @@ -23,7 +22,6 @@ jobs:
matrix:
node-version: [16, 18]
runs-on: ubuntu-20.04
container: node:14
steps:
- uses: actions/checkout@v2
- name: Use Node.js
Expand Down Expand Up @@ -53,7 +51,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 18
- run: yarn --frozen-lockfile
Expand Down
1 change: 1 addition & 0 deletions changelog.d/452.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `release.sh` script to automate the release process.
5 changes: 0 additions & 5 deletions scripts/changelog-release.sh

This file was deleted.

47 changes: 47 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
# This script will run towncrier to and generate a release commit, tag and push to the origin.

if ! command -v jq &> /dev/null
then
echo "You must install jq to use this script"
exit
fi

VERSION=`jq -r .version package.json`
TAG="$VERSION"

if [[ "`git branch --show-current`" != "develop" ]]; then
echo "You must be on the develop branch to run this command."
exit 1
fi

if [ $(git tag -l "$TAG") ]; then
echo "Tag $TAG already exists, not continuing."
exit 1
fi

echo "Drafting a new release"
towncrier build --draft --version $VERSION> draft-release.txt
cat draft-release.txt

read -p "Happy with the changelog? <y/N> " prompt
if [[ $prompt != "y" && $prompt != "Y" && $prompt != "yes" && $prompt != "Yes" ]]
then
exit 0
fi

echo "Committing version"
towncrier build --version $VERSION
git commit CHANGELOG.md changelog.d/ package.json -m $TAG

echo "Proceeding to generate tags"
cat draft-release.txt | git tag --force -m - -s $TAG
rm draft-release.txt
echo "Generated tag $TAG"

echo "Pushing to origin"
git push origin $TAG
# Push develop too
git push

echo "The CI to generate a release is now running. Check https://github.com/matrix-org/matrix-appservice-bridge/releases and publish the release when it's ready."

0 comments on commit a6be350

Please sign in to comment.