From 2b014d9fbcb39113742653dfeba1b7305c50727e Mon Sep 17 00:00:00 2001 From: Ido David <36866853+ido-namely@users.noreply.github.com> Date: Tue, 13 Sep 2022 12:01:01 -0400 Subject: [PATCH] Fix the workflows so that we can auto release a new major version (#336) --- .../{prerelease.yml => docker_prerelease.yml} | 6 +-- .github/workflows/docker_release.yml | 54 +++++++++++++++++++ .../{grpc_release.yml => gh_grpc_release.yml} | 16 +++++- .github/workflows/release.yml | 49 ----------------- README.md | 5 +- 5 files changed, 74 insertions(+), 56 deletions(-) rename .github/workflows/{prerelease.yml => docker_prerelease.yml} (91%) create mode 100644 .github/workflows/docker_release.yml rename .github/workflows/{grpc_release.yml => gh_grpc_release.yml} (79%) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/prerelease.yml b/.github/workflows/docker_prerelease.yml similarity index 91% rename from .github/workflows/prerelease.yml rename to .github/workflows/docker_prerelease.yml index 74fbdb19..6eb58641 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/docker_prerelease.yml @@ -1,6 +1,6 @@ -# Build, Tag & Push a new release to dockerhub off of a tag +# Build, Tag & Push a new prerelease to dockerhub off of a tag -name: Pre-release +name: Docker Pre-release on: push: @@ -9,7 +9,7 @@ on: jobs: - prerelease-build: + docker_prerelease: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/docker_release.yml b/.github/workflows/docker_release.yml new file mode 100644 index 00000000..4f052ec3 --- /dev/null +++ b/.github/workflows/docker_release.yml @@ -0,0 +1,54 @@ +# Build, Tag & Push a new release to dockerhub off of a new pushed tag or gh_grpc_release.yml workflow + +name: Docker Release + +on: + workflow_call: + inputs: + release_version: + required: true + type: string + push: + tags: + - 'v[0-9]+.[0-9]+_[0-9]+' + + +jobs: + docker_release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + + - uses: nelonoel/branch-name@v1.0.1 + + - name: Docker Login + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USER }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN" + + - name: Get Version + id: get_version + run: | + version="" + if [[ ${{ github.event_name }} == "pull_request" ]]; then + version=${{ inputs.release_version }} + fi + if [[ ${{ github.event_name }} == "push" ]]; then + version=${GITHUB_REF#refs/*/} + fi + # Strip "v" prefix from tag name and set to output var + echo ::set-output name=version::${version#v} + - name: Build and Tag + if: success() + env: + VERSION: ${{ steps.get_version.outputs.version }} + run: make tag-latest + + - name: Push + if: success() + env: + VERSION: ${{ steps.get_version.outputs.version }} + run: make push-latest diff --git a/.github/workflows/grpc_release.yml b/.github/workflows/gh_grpc_release.yml similarity index 79% rename from .github/workflows/grpc_release.yml rename to .github/workflows/gh_grpc_release.yml index 66b13b72..e8468033 100644 --- a/.github/workflows/grpc_release.yml +++ b/.github/workflows/gh_grpc_release.yml @@ -9,7 +9,7 @@ # Note that once a new release is created in GH, a separate workflow will take care of releasing new docker images to dockerhub accordingly. -name: New gPRC Release +name: Github gRPC Release on: pull_request: @@ -19,9 +19,11 @@ on: - 'master' jobs: - new_release: + new_gh_release: if: github.event.pull_request.merged == true && github.head_ref == 'renovate/grpc-major-upgrade' runs-on: ubuntu-latest + outputs: + version: ${{ steps.set_version_as_output.outputs.version }} steps: # checkout the repo - uses: actions/checkout@v3 @@ -35,10 +37,20 @@ jobs: VER=$(pcregrep -o1 "^GRPC_VERSION=\\$\{GRPC_VERSION:-(.*?)\\}$" variables.sh) # This makes the value accessible from env.Version echo "VERSION=v${VER}_0" >> $GITHUB_ENV + - name: Set version value as output + id: set_version_as_output + run: + echo ::set-output name=version::${{ env.VERSION }} - name: Create new release if: success() env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: gh release create ${{ env.VERSION }} --generate-notes --repo $GITHUB_REPOSITORY + new_docker_release: + needs: new_gh_release + uses: ./.github/workflows/docker_release.yml + with: + release_version: ${{ needs.new_gh_release.outputs.version }} + secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index d0c07a06..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,49 +0,0 @@ -# Build, Tag & Push a new release to dockerhub off of a tag - -name: Release - -on: - push: - tags: - - 'v[0-9]+.[0-9]+_[0-9]+' - - -jobs: - release-build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - - uses: nelonoel/branch-name@v1.0.1 - - - name: Docker Login - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USER }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN" - - - name: Create Version - id: version - if: success() - run: | - # TODO: find a better way to version from tags - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - # set to output var - echo ::set-output name=VERSION::${VERSION} - - - name: Build and Tag - if: success() - env: - VERSION: ${{ steps.version.outputs.VERSION }} - run: make tag-latest - - - name: Push - if: success() - env: - VERSION: ${{ steps.version.outputs.VERSION }} - run: make push-latest diff --git a/README.md b/README.md index d40fbd5b..ac3c94f7 100755 --- a/README.md +++ b/README.md @@ -302,8 +302,9 @@ Please read more [here](./.github/renovate.md). ### Release -Any new gRPC version based release is handled automatically once the relevant [Renovate](https://www.mend.io/free-developer-tools/renovate/) branch is merged to master -via the CI (Github Action). A patch release should be created manually in Github and the CI workflow will take care of the rest. +* A new gRPC version based release is handled automatically once the relevant [Renovate](https://www.mend.io/free-developer-tools/renovate/) branch is merged to master +via the CI (Github Action). +* A patch/release candidate release should be created manually in Github and the CI workflow will take care of the rest. #### Contributors