From 6a225b75333c0ebd79f8fc63561da2cf5bbb086b Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 21 Mar 2023 13:07:58 +0000 Subject: [PATCH 1/3] Add release script and workflow --- .github/workflows/release.yml | 26 ++++++++++++++++++ scripts/release.sh | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100755 scripts/release.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..4a7e217e0 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 000000000..c1c413216 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,50 @@ +#!/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 '(?<=git@github.com:)(.*)(?=.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? " 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 +# 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/$REPO_NAME/releases and publish the release when it's ready." \ No newline at end of file From ff79b80f2ca9e4a3d8c38ec49fc37484496c31fc Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 21 Mar 2023 13:09:16 +0000 Subject: [PATCH 2/3] remove comments --- scripts/release.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index c1c413216..988ee906f 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -35,16 +35,17 @@ fi echo "Committing version" towncrier build --version $VERSION -# git commit CHANGELOG.md changelog.d/ package.json -m $TAG +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 +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 +git push origin $TAG + +# Push to main branch too +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." \ No newline at end of file From 11fe446df9a80bb077d2f679e64eed3902a48b05 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 21 Mar 2023 13:10:40 +0000 Subject: [PATCH 3/3] changelog --- changelog.d/667.misc | 1 + scripts/release.sh | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 changelog.d/667.misc diff --git a/changelog.d/667.misc b/changelog.d/667.misc new file mode 100644 index 000000000..b853c100b --- /dev/null +++ b/changelog.d/667.misc @@ -0,0 +1 @@ +Add release.sh script and release.yml workflow to make the release process easier. \ No newline at end of file diff --git a/scripts/release.sh b/scripts/release.sh index 988ee906f..91c207ae2 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -44,8 +44,6 @@ echo "Generated tag $TAG" echo "Pushing to origin" git push origin $TAG - -# Push to main branch too 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." \ No newline at end of file