From 0662d8d077561502b45d126318c750bf9cf35508 Mon Sep 17 00:00:00 2001 From: Vui Lam Date: Fri, 7 Apr 2023 16:52:59 -0700 Subject: [PATCH] Add release workflow to produce gh release on tag Signed-off-by: Vui Lam --- .github/workflows/release.yaml | 146 +++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..b67dd0850 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,146 @@ +name: Release + +on: + push: + branches: + - "!not_activated_on_branches!*" + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+-*" + +jobs: + + build: + name: Release + runs-on: ubuntu-latest + steps: + - name: Free some disk space on runner + run: | + df -h + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf /usr/local/share/boost + sudo rm -rf /usr/lib/jvm + sudo rm -rf /usr/lib/firefox + sudo rm -rf /opt/microsoft/powershell + sudo rm -rf /opt/hostedtoolcache + echo "free space after cleanup:" + df -h + + - name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version: 1.18 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Generate details for creating release notes + id: generate-release-details + shell: bash + run: | + set -o xtrace + RELEASE_BRANCH="main" + RELEASE_VERSION=${GITHUB_REF#refs/*/} + major=$(echo "$RELEASE_VERSION" | sed 's/^v\(.*\)/\1/' | cut -d. -f1) + minor=$(echo "$RELEASE_VERSION" | cut -d. -f2) + revision=$(echo "$RELEASE_VERSION" | cut -d. -f3 | cut -d- -f1) + if [ "$revision" -gt 0 ];then + revision=$(($revision-1)) + RELEASE_BRANCH="release-${major}.${minor}" + elif [ "$minor" -gt 0 ]; then + minor=$(($minor-1)) + elif [ "$major" -gt 0 ]; then + major=$(($major-1)) + else + echo "Please validate that the tag release version(${RELEASE_VERSION}) conforms to semver." + exit 1 + fi + git log -3 --format=oneline + LAST_TAG="v${major}.${minor}.${revision}" + # remove after first release + LAST_TAG="v0.0.1" + echo "Last release tag - $LAST_TAG" + START_SHA=$(git rev-list -n 1 $LAST_TAG) + echo "Release note generator start SHA - $START_SHA" + END_SHA=$(git rev-list -n 1 $RELEASE_VERSION) + echo "Release note generator end SHA - $END_SHA" + + echo "::set-output name=start-sha::$START_SHA" + echo "::set-output name=end-sha::$END_SHA" + echo "::set-output name=release-version::$RELEASE_VERSION" + echo "::set-output name=prev-release-version::$LAST_TAG" + echo "::set-output name=repo-name::$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" + echo "::set-output name=repo-org::$(echo '${{ github.repository }}' | awk -F '/' '{print $1}')" + echo "::set-output name=release-branch::$RELEASE_BRANCH" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install release-note dependency + run: | + go install k8s.io/release/cmd/release-notes@v0.13.0 + + - name: Get Time + id: time + uses: nanzm/get-time-action@v1.1 + with: + format: 'YYYYMMDDHHmmss' + + - name: Generate release notes + id: get-release-notes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + release-notes \ + --github-base-url https://github.com \ + --org ${{ steps.generate-release-details.outputs.repo-org }} \ + --repo ${{ steps.generate-release-details.outputs.repo-name }} \ + --branch ${{ steps.generate-release-details.outputs.release-branch }} \ + --required-author "" \ + --start-sha ${{ steps.generate-release-details.outputs.start-sha }} \ + --end-sha ${{ steps.generate-release-details.outputs.end-sha }} \ + --output /tmp/${{ steps.time.outputs.time }}-bin-notes + + - name: Get Github Release notes + uses: octokit/request-action@v2.x + id: get-github-release-notes + with: + route: POST /repos/{owner}/{repo}/releases/generate-notes + owner: ${{ steps.generate-release-details.outputs.repo-org }} + repo: ${{ steps.generate-release-details.outputs.repo-name }} + tag_name: ${{ steps.generate-release-details.outputs.release-version }} + previous_tag_name: ${{ steps.generate-release-details.outputs.prev-release-version }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: 'Identify New Contributors Section' + id: get-new-contributors + run: | + githubOutput="/tmp/${{ steps.time.outputs.time }}-github-output" + echo "${{ fromJson(steps.get-github-release-notes.outputs.data).body }}" > "$githubOutput" + + - name: Generate the release notes + shell: bash + run: | + NEW_CONTRIBUTORS=$(sed -n '/## New Contributors/,$p' /tmp/${{ steps.time.outputs.time }}-github-output) + RELEASE_TOOL_NOTES=$(sed 's/### Uncategorized/### Miscellaneous/g' /tmp/${{ steps.time.outputs.time }}-bin-notes) + RELEASE_NOTES=$(cat <<-END + $RELEASE_TOOL_NOTES + + $NEW_CONTRIBUTORS + END + ) + echo "$RELEASE_NOTES" + echo "RELEASE_NOTES<> $GITHUB_ENV + echo "$RELEASE_NOTES" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - id: create_draft_release + name: Create Draft Release + uses: softprops/action-gh-release@v1 + with: + draft: true + body: ${{ env.RELEASE_NOTES }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}