From 0061cfdb8e0957d7cdc5fceb5abe7ee6ecbb7762 Mon Sep 17 00:00:00 2001 From: Giovanni Toraldo Date: Thu, 3 Aug 2023 14:26:46 +0200 Subject: [PATCH] OPSEXP-1709 Automate release (#303) --- .github/workflows/release.yml | 47 ++++++++++++++++++++++++++++ docs/README.md | 6 +--- release.sh | 58 +++++++++-------------------------- version.txt | 1 + 4 files changed, 64 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 version.txt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..3af803e2b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: Release + +on: + pull_request: + types: + - closed + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: master + token: ${{ secrets.BOT_GITHUB_TOKEN }} + + - name: Fetch next version + run: | + echo "VERSION=$(cat version.txt)" >> $GITHUB_ENV + + - name: Check if release is necessary + id: release_guard + run: | + if git tag | grep -q "^${VERSION}$"; then + echo "do_release=false" >> $GITHUB_OUTPUT + else + echo "do_release=true" >> $GITHUB_OUTPUT + fi + + - name: Apply release changes + if: steps.release_guard.outputs.do_release == 'true' + run: | + ./release.sh $VERSION + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: master + skip_checkout: true + commit_message: Release ${{ env.VERSION }} + + - name: Generate release notes + if: steps.release_guard.outputs.do_release == 'true' + env: + GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + run: gh release create "$VERSION" --generate-notes -t "$VERSION" diff --git a/docs/README.md b/docs/README.md index 6804b78c2..11d07b917 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1307,8 +1307,4 @@ brew install coreutils ## Release -Run the release script to release a new version from this repository: - -```sh -./release.sh v1.2.3 -``` +Bump version defined in [version.txt](/version.txt) during a PR, release workflow is triggered automatically. diff --git a/release.sh b/release.sh index e2a37b0b3..74f9c4add 100755 --- a/release.sh +++ b/release.sh @@ -1,54 +1,26 @@ -#!/bin/bash -e +#!/bin/bash +set -e -if ! command -v gh &> /dev/null -then - echo "gh command should be available for running this script" - echo "see https://github.com/cli/cli/" - exit 1 +if [ -z "$GITHUB_WORKSPACE" ]; then + echo "You should not run anymore this script from your machine, see updated README" + exit 1 fi -gh auth status - if [ -z "$1" ] || [[ ! "$1" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then - echo 'First argument should be next version to release with a leading v char' - exit 1 -fi - -echo "This script will switch to master and pull origin/master to make sure you are in sync" -read -p "Are you sure? " -n 1 -r -echo -if [[ ! $REPLY =~ ^[Yy]$ ]]; then - exit 1 + echo 'First argument should be next version to release with a leading v char' + exit 1 fi -git fetch -git checkout master -git pull origin master --no-rebase - CURRENT_VERSION=$(git tag | sort -r --version-sort | head -n1) -echo "Current version is $CURRENT_VERSION" -echo "Going to create a PR to release $1" - -git checkout -b "$1" - -if [[ "$OSTYPE" == "darwin"* ]]; then - grep -Rl "Alfresco/alfresco-build-tools.*@$CURRENT_VERSION" | xargs sed -i '' -e "s/\(Alfresco\/alfresco-build-tools.*@\)$CURRENT_VERSION/\1$1/g" - sed -i '' -e "s/$CURRENT_VERSION/$1/" .pre-commit-config.yaml -else - grep -Rl "Alfresco/alfresco-build-tools.*@$CURRENT_VERSION" | xargs sed -i -e "s/\(Alfresco\/alfresco-build-tools.*@\)$CURRENT_VERSION/\1$1/g" - sed -i -e "s/$CURRENT_VERSION/$1/" .pre-commit-config.yaml +if [ -z "$CURRENT_VERSION" ]; then + echo "Can't retrieve tags" + exit 1 fi -grep -Rl "$1" | xargs git add - -git commit -m "Prepare to release $1" -git push origin "$1" +echo "Current version is $CURRENT_VERSION" +echo "Going to flip refs to $1" -gh pr create -a '@me' -t "Release $1" -b '' -git checkout master +grep -Rl "Alfresco/alfresco-build-tools.*@$CURRENT_VERSION" | xargs sed -i -e "s/\(Alfresco\/alfresco-build-tools.*@\)$CURRENT_VERSION/\1$1/g" +sed -i -e "s/$CURRENT_VERSION/$1/" .pre-commit-config.yaml -echo "" -echo "Once PR is merged execute locally:" -echo "- git pull origin master" -echo "- gh release create $1 --generate-notes -t $1" -echo "" +echo "Rename completed succesfully" diff --git a/version.txt b/version.txt new file mode 100644 index 000000000..b77e3cc58 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +v2.8.0