From a4aa12caae943da2ffb1cdb1a38b224130ddb610 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 3 Jul 2023 11:56:29 -0500 Subject: [PATCH] Added GitHub Action release script On passing tests on master: 1. Update "vN" branch 2. Create release notes containing all non-merge commits 3. If patch release, publish release 4. If >=minor release, create draft release but let a human publish This is based on the current release script in the core littlefs repo. --- .github/workflows/release.yml | 108 ++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..16dc983 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,108 @@ +name: release +on: + workflow_run: + workflows: [test] + branches: [master] + types: [completed] + +defaults: + run: + shell: bash -euv -o pipefail {0} + +jobs: + release: + runs-on: ubuntu-22.04 + + # need to manually check for a couple things + # - tests passed? + # - we are the most recent commit on master? + if: ${{github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.head_sha == github.sha}} + + steps: + - uses: actions/checkout@v2 + with: + ref: ${{github.event.workflow_run.head_sha}} + # need workflow access since we push branches + # containing workflows + token: ${{secrets.BOT_TOKEN}} + # need all tags + fetch-depth: 0 + + - name: find-version + run: | + # rip version from lfs_fuse.c + LFS_FUSE_VERSION="$( \ + grep -o '^#define LFS_FUSE_VERSION .*$' lfs_fuse.c \ + | awk '{print $3}')" + LFS_FUSE_VERSION_MAJOR="$((0xffff & ($LFS_FUSE_VERSION >> 16)))" + LFS_FUSE_VERSION_MINOR="$((0xffff & ($LFS_FUSE_VERSION >> 0)))" + + # find a new patch version based on what we find in our tags + LFS_FUSE_VERSION_PATCH="$( \ + ( git describe --tags --abbrev=0 \ + --match="v$LFS_FUSE_VERSION_MAJOR.$LFS_FUSE_VERSION_MINOR.*" \ + || echo 'v0.0.-1' ) \ + | awk -F '.' '{print $3+1}')" + + # found new version + LFS_FUSE_VERSION="v$LFS_FUSE_VERSION_MAJOR` + `.$LFS_FUSE_VERSION_MINOR` + `.$LFS_FUSE_VERSION_PATCH" + echo "LFS_FUSE_VERSION=$LFS_FUSE_VERSION" + echo "LFS_FUSE_VERSION=$LFS_FUSE_VERSION" >> $GITHUB_ENV + echo "LFS_FUSE_VERSION_MAJOR=$LFS_FUSE_VERSION_MAJOR" >> $GITHUB_ENV + echo "LFS_FUSE_VERSION_MINOR=$LFS_FUSE_VERSION_MINOR" >> $GITHUB_ENV + echo "LFS_FUSE_VERSION_PATCH=$LFS_FUSE_VERSION_PATCH" >> $GITHUB_ENV + + # try to find previous version? + - name: find-prev-version + continue-on-error: true + run: | + LFS_FUSE_PREV_VERSION="$( \ + git describe --tags --abbrev=0 --match 'v*' \ + || true)" + echo "LFS_FUSE_PREV_VERSION=$LFS_FUSE_PREV_VERSION" + echo "LFS_FUSE_PREV_VERSION=$LFS_FUSE_PREV_VERSION" >> $GITHUB_ENV + + # find changes from history + - name: create-changes + run: | + [ -n "$LFS_FUSE_PREV_VERSION" ] || exit 0 + # use explicit link to github commit so that release notes can + # be copied elsewhere + git log "$LFS_FUSE_PREV_VERSION.." \ + --grep='^Merge' --invert-grep \ + --format="format:[\`%h\`](` + `https://github.com/$GITHUB_REPOSITORY/commit/%h) %s" \ + > changes.txt + echo "CHANGES:" + cat changes.txt + + # create and update major branches (vN) + - name: create-major-branches + run: | + # create major branch + git branch "v$LFS_FUSE_VERSION_MAJOR" HEAD + + # push! + git push --atomic origin "v$LFS_FUSE_VERSION_MAJOR" + + # build release notes + - name: create-release + run: | + # create release and patch version tag (vN.N.N) + # only draft if not a patch release + [ -e changes.txt ] && cat changes.txt >> release.txt + cat release.txt + + curl -sS -X POST -H "authorization: token ${{secrets.BOT_TOKEN}}" \ + "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \ + -d "$(jq -n --rawfile release release.txt '{ + tag_name: env.LFS_FUSE_VERSION, + name: env.LFS_FUSE_VERSION | rtrimstr(".0"), + target_commitish: "${{github.event.workflow_run.head_sha}}", + draft: env.LFS_FUSE_VERSION | endswith(".0"), + body: $release, + }' | tee /dev/stderr)" +