|
| 1 | +name: release |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: [test] |
| 5 | + branches: [master] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +defaults: |
| 9 | + run: |
| 10 | + shell: bash -euv -o pipefail {0} |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-22.04 |
| 15 | + |
| 16 | + # need to manually check for a couple things |
| 17 | + # - tests passed? |
| 18 | + # - we are the most recent commit on master? |
| 19 | + if: ${{github.event.workflow_run.conclusion == 'success' && |
| 20 | + github.event.workflow_run.head_sha == github.sha}} |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v2 |
| 24 | + with: |
| 25 | + ref: ${{github.event.workflow_run.head_sha}} |
| 26 | + # need workflow access since we push branches |
| 27 | + # containing workflows |
| 28 | + token: ${{secrets.BOT_TOKEN}} |
| 29 | + # need all tags |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: find-version |
| 33 | + run: | |
| 34 | + # rip version from lfs_fuse.c |
| 35 | + LFS_FUSE_VERSION="$( \ |
| 36 | + grep -o '^#define LFS_FUSE_VERSION .*$' lfs_fuse.c \ |
| 37 | + | awk '{print $3}')" |
| 38 | + LFS_FUSE_VERSION_MAJOR="$((0xffff & ($LFS_FUSE_VERSION >> 16)))" |
| 39 | + LFS_FUSE_VERSION_MINOR="$((0xffff & ($LFS_FUSE_VERSION >> 0)))" |
| 40 | +
|
| 41 | + # find a new patch version based on what we find in our tags |
| 42 | + LFS_FUSE_VERSION_PATCH="$( \ |
| 43 | + ( git describe --tags --abbrev=0 \ |
| 44 | + --match="v$LFS_FUSE_VERSION_MAJOR.$LFS_FUSE_VERSION_MINOR.*" \ |
| 45 | + || echo 'v0.0.-1' ) \ |
| 46 | + | awk -F '.' '{print $3+1}')" |
| 47 | +
|
| 48 | + # found new version |
| 49 | + LFS_FUSE_VERSION="v$LFS_FUSE_VERSION_MAJOR` |
| 50 | + `.$LFS_FUSE_VERSION_MINOR` |
| 51 | + `.$LFS_FUSE_VERSION_PATCH" |
| 52 | + echo "LFS_FUSE_VERSION=$LFS_FUSE_VERSION" |
| 53 | + echo "LFS_FUSE_VERSION=$LFS_FUSE_VERSION" >> $GITHUB_ENV |
| 54 | + echo "LFS_FUSE_VERSION_MAJOR=$LFS_FUSE_VERSION_MAJOR" >> $GITHUB_ENV |
| 55 | + echo "LFS_FUSE_VERSION_MINOR=$LFS_FUSE_VERSION_MINOR" >> $GITHUB_ENV |
| 56 | + echo "LFS_FUSE_VERSION_PATCH=$LFS_FUSE_VERSION_PATCH" >> $GITHUB_ENV |
| 57 | +
|
| 58 | + # try to find previous version? |
| 59 | + - name: find-prev-version |
| 60 | + continue-on-error: true |
| 61 | + run: | |
| 62 | + LFS_FUSE_PREV_VERSION="$( \ |
| 63 | + git describe --tags --abbrev=0 --match 'v*' \ |
| 64 | + || true)" |
| 65 | + echo "LFS_FUSE_PREV_VERSION=$LFS_FUSE_PREV_VERSION" |
| 66 | + echo "LFS_FUSE_PREV_VERSION=$LFS_FUSE_PREV_VERSION" >> $GITHUB_ENV |
| 67 | +
|
| 68 | + # find changes from history |
| 69 | + - name: create-changes |
| 70 | + run: | |
| 71 | + [ -n "$LFS_FUSE_PREV_VERSION" ] || exit 0 |
| 72 | + # use explicit link to github commit so that release notes can |
| 73 | + # be copied elsewhere |
| 74 | + git log "$LFS_FUSE_PREV_VERSION.." \ |
| 75 | + --grep='^Merge' --invert-grep \ |
| 76 | + --format="format:[\`%h\`](` |
| 77 | + `https://github.com/$GITHUB_REPOSITORY/commit/%h) %s" \ |
| 78 | + > changes.txt |
| 79 | + echo "CHANGES:" |
| 80 | + cat changes.txt |
| 81 | +
|
| 82 | + # create and update major branches (vN) |
| 83 | + - name: create-major-branches |
| 84 | + run: | |
| 85 | + # create major branch |
| 86 | + git branch "v$LFS_FUSE_VERSION_MAJOR" HEAD |
| 87 | +
|
| 88 | + # push! |
| 89 | + git push --atomic origin "v$LFS_FUSE_VERSION_MAJOR" |
| 90 | +
|
| 91 | + # build release notes |
| 92 | + - name: create-release |
| 93 | + run: | |
| 94 | + # create release and patch version tag (vN.N.N) |
| 95 | + # only draft if not a patch release |
| 96 | + touch release.txt |
| 97 | + [ -e changes.txt ] && cat changes.txt >> release.txt |
| 98 | + cat release.txt |
| 99 | +
|
| 100 | + curl -sS -X POST -H "authorization: token ${{secrets.BOT_TOKEN}}" \ |
| 101 | + "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \ |
| 102 | + -d "$(jq -n --rawfile release release.txt '{ |
| 103 | + tag_name: env.LFS_FUSE_VERSION, |
| 104 | + name: env.LFS_FUSE_VERSION | rtrimstr(".0"), |
| 105 | + target_commitish: "${{github.event.workflow_run.head_sha}}", |
| 106 | + draft: env.LFS_FUSE_VERSION | endswith(".0"), |
| 107 | + body: $release, |
| 108 | + }' | tee /dev/stderr)" |
| 109 | +
|
0 commit comments