Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add release script #667

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
env:
REF_NAME: ${{ github.ref_name }}
run: |
git fetch --tags --force
RELEASE_NAME="${REF_NAME} $(date +'%Y-%m-%d')"
git tag -l --format='%(contents:body)' "${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
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions changelog.d/667.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add release.sh script and release.yml workflow to make the release process easier.
49 changes: 49 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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"
HEAD_BRANCH=`git remote show origin | sed -n '/HEAD branch/s/.*: //p'`
REPO_NAME=`git remote show origin -n | grep -m 1 -oP '(?<[email protected]:)(.*)(?=.git)'`

if [[ "`git branch --show-current`" != $HEAD_BRANCH ]]; 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
rm draft-release.txt
exit 0
fi

echo "Committing version"
towncrier build --version $VERSION
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved
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
git push

echo "The CI to generate a release is now running. Check https://github.com/$REPO_NAME/releases and publish the release when it's ready."