Skip to content

Commit

Permalink
OPSEXP-1709 Automate release (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
gionn authored Aug 3, 2023
1 parent d862c52 commit 0061cfd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 48 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 1 addition & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
58 changes: 15 additions & 43 deletions release.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v2.8.0

0 comments on commit 0061cfd

Please sign in to comment.