From a9df6638697cada35d92fdfe79296ba696d1ddf4 Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 10:53:11 -0400 Subject: [PATCH 1/9] Modifications to latest CI change based on GH Actions --- .github/workflows/pr_master.yml | 9 +++++- .github/workflows/prerelease.yml | 49 ++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 8 ++++-- build.sh | 2 +- push.sh | 2 +- variables.sh | 3 +- 6 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/prerelease.yml diff --git a/.github/workflows/pr_master.yml b/.github/workflows/pr_master.yml index d84e939f..b60a4903 100644 --- a/.github/workflows/pr_master.yml +++ b/.github/workflows/pr_master.yml @@ -29,7 +29,14 @@ jobs: DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN" + - name: Create Build Version + id: build_version + if: success() + run: | + echo ::set-output name=SHA_SHORT::$(git rev-parse --short HEAD) + - name: Build + if: success() env: - BUILD_VERSION: ${{ env.COMMIT_HASH }} + BUILD_VERSION: ${{ steps.version.outputs.SHA_SHORT }} run: make build diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml new file mode 100644 index 00000000..2f9caf58 --- /dev/null +++ b/.github/workflows/prerelease.yml @@ -0,0 +1,49 @@ +# Build, Tag & Push a new release to dockerhub off of a tag + +name: Pre-release + +on: + push: + tags: + - 'v[0-9]+.[0-9]+_[0-9]+-rc.[0-9]+"' + + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + 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 + + - name: Push + if: success() + env: + VERSION: ${{ steps.version.outputs.VERSION }} + run: make push diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 75d8b6a0..d811f1bf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,7 +5,7 @@ name: Release on: push: tags: - - 'v*' + - 'v[0-9]+.[0-9]+_[0-9]+"' jobs: @@ -26,6 +26,7 @@ jobs: - name: Create Version id: version + if: success() run: | # TODO: find a better way to version from tags # Strip git ref prefix from version @@ -36,12 +37,13 @@ jobs: echo ::set-output name=VERSION::${VERSION} - name: Build and Tag + if: success() env: - BUILD_VERSION: ${{ steps.version.outputs.VERSION }} + VERSION: ${{ steps.version.outputs.VERSION }} run: make tag-latest - name: Push if: success() env: - BUILD_VERSION: ${{ steps.version.outputs.VERSION }} + VERSION: ${{ steps.version.outputs.VERSION }} run: make push-latest diff --git a/build.sh b/build.sh index 32d01704..0295a390 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,7 @@ source ./variables.sh for build in ${BUILDS[@]}; do - tag=${CONTAINER}/${build}:${BUILD_VERSION} + tag=${CONTAINER}/${build}:${VERSION} echo "building ${build} container with tag ${tag}" docker build -t ${tag} \ -f Dockerfile \ diff --git a/push.sh b/push.sh index 790593b4..14edd0c4 100755 --- a/push.sh +++ b/push.sh @@ -3,7 +3,7 @@ source ./variables.sh for build in ${BUILDS[@]}; do - tag=${CONTAINER}/${build}:${BUILD_VERSION} + tag=${CONTAINER}/${build}:${VERSION} echo "pushing ${tag}" docker push ${tag} diff --git a/variables.sh b/variables.sh index 5ef5f96e..9aa34d79 100755 --- a/variables.sh +++ b/variables.sh @@ -17,4 +17,5 @@ NODE_VERSION=${NODE_VERSION:-14} NODE_GRPC_TOOLS_NODE_PROTOC_TS_VERSION=${NODE_GRPC_TOOLS_NODE_PROTOC_TS_VERSION:-5.1.3} NODE_GRPC_TOOLS_VERSION=${NODE_GRPC_TOOLS_VERSION:-1.11.1} NODE_PROTOC_GET_GRPC_WEB_VERSION=${NODE_PROTOC_GET_GRPC_WEB_VERSION:-1.2.1} -BUILD_VERSION="${BUILD_VERSION:-${GRPC_VERSION}_0}" +BUILD_VERSION="${BUILD_VERSION:-local}" +VERSION="${VERSION:-${GRPC_VERSION}_${BUILD_VERSION}}" From 1af775664a349205cf571e014cd03271a0fb6416 Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 10:54:25 -0400 Subject: [PATCH 2/9] remove unused var --- .github/workflows/pr_master.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pr_master.yml b/.github/workflows/pr_master.yml index b60a4903..6e8e39d0 100644 --- a/.github/workflows/pr_master.yml +++ b/.github/workflows/pr_master.yml @@ -14,8 +14,6 @@ on: jobs: build: runs-on: ubuntu-latest - env: - COMMIT_HASH: ${{ github.sha }} steps: - uses: actions/checkout@v2 with: From 3ce5ab68a140146f9951543bf466bc6b548b4add Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 10:55:30 -0400 Subject: [PATCH 3/9] rename gh action step --- .github/workflows/pr_master.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr_master.yml b/.github/workflows/pr_master.yml index 6e8e39d0..c96cc1f9 100644 --- a/.github/workflows/pr_master.yml +++ b/.github/workflows/pr_master.yml @@ -27,8 +27,8 @@ jobs: DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN" - - name: Create Build Version - id: build_version + - name: Create Short Commit Sha + id: sha_short if: success() run: | echo ::set-output name=SHA_SHORT::$(git rev-parse --short HEAD) From 7fc2f300840c28c7972688f30fcc0a36fca7a5a2 Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 11:35:57 -0400 Subject: [PATCH 4/9] update release instructions --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dba3f080..e172e5ad 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # gRPC/Protocol Buffer Compiler Containers -[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/namely/docker-protoc/Build/master?style=flat-square)](https://github.com/namely/docker-protoc/actions?query=workflow%3ABuild) +[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/namely/docker-protoc/Build/master?style=flat-square)](https://github.com/namely/docker-protoc/actions?query=workflow%3AMaster) This repository contains support for various Docker images that wrap `protoc`, `prototool`, `grpc_cli` commands with [gRPC](https://github.com/grpc/grpc) support @@ -288,7 +288,9 @@ Thank you!! Namely employees can merge PRs and cut a release/pre-release by drafting a new Github release and publishing them. The release name should follow the same tag conventions described in [this doc](#tag-conventions) and the gRPC version in the release name must match the `GRPC_VERSION` configured in [variables.sh](./variables.sh). -Once a new Github release is published, new images will be published to [DockerHub](https://hub.docker.com/u/namely/) via CI. +A valid release/pre-release will be of the form `v${GRPC_VERSION}_${BUILD_VERSION}`/`v${GRPC_VERSION}_${BUILD_VERSION}-rc.${RC_VERSION}` respectively. +e.g `1.37_2`, `1.38_0-rc.3`. +Once a new **valid** Github release is published, new images will be published to [DockerHub](https://hub.docker.com/u/namely/) via CI. ## Docker Troubleshooting From 04cf1ba0a488256bd2cde388afff767a6c621299 Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 11:41:59 -0400 Subject: [PATCH 5/9] separate pr and master releases --- .../workflows/{pr_master.yml => master.yml} | 5 +-- .github/workflows/pr.yml | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) rename .github/workflows/{pr_master.yml => master.yml} (93%) create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/pr_master.yml b/.github/workflows/master.yml similarity index 93% rename from .github/workflows/pr_master.yml rename to .github/workflows/master.yml index c96cc1f9..31b6de35 100644 --- a/.github/workflows/pr_master.yml +++ b/.github/workflows/master.yml @@ -1,10 +1,9 @@ -# build the image on PRs and master +# build the image on master -name: PR +name: Master on: - pull_request: push: branches: - master diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..dc336858 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,40 @@ + +# build the image on PRs + +name: PR + +on: + pull_request: + paths-ignore: + - 'README.md' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + 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 Short Commit Sha + id: sha_short + if: success() + run: | + echo ::set-output name=SHA_SHORT::$(git rev-parse --short HEAD) + - name: Check outputs + run: echo ${{ steps.vars.outputs.sha_short }} + + - name: Build + if: success() + env: + BUILD_VERSION: ${{ steps.version.outputs.SHA_SHORT }} + run: echo ${{ env.BUILD_VERSION }} + #run: make build From ca638ed7b1f70c257e05b95945532374b980db21 Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 11:45:06 -0400 Subject: [PATCH 6/9] try to fix short commit sha calc --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index dc336858..ac8c6825 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -28,7 +28,7 @@ jobs: id: sha_short if: success() run: | - echo ::set-output name=SHA_SHORT::$(git rev-parse --short HEAD) + echo "::set-output name=SHA_SHORT::$(git rev-parse --short HEAD)" - name: Check outputs run: echo ${{ steps.vars.outputs.sha_short }} From b917601d5bff918b8c3181eaae2ff0debc6673c9 Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 11:48:45 -0400 Subject: [PATCH 7/9] try to fix short commit sha calc --- .github/workflows/pr.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ac8c6825..c9fcc487 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -27,8 +27,7 @@ jobs: - name: Create Short Commit Sha id: sha_short if: success() - run: | - echo "::set-output name=SHA_SHORT::$(git rev-parse --short HEAD)" + run: echo "::set-output name=SHA_SHORT::$(git rev-parse --short HEAD)" - name: Check outputs run: echo ${{ steps.vars.outputs.sha_short }} From f55029d51907a19c9cdef507ee84c12d0db4f1ef Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 11:51:50 -0400 Subject: [PATCH 8/9] try to fix short commit sha calc --- .github/workflows/pr.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c9fcc487..badf42f6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -27,13 +27,13 @@ jobs: - name: Create Short Commit Sha id: sha_short if: success() - run: echo "::set-output name=SHA_SHORT::$(git rev-parse --short HEAD)" + run: echo ::set-output name=SHA_SHORT::$(git rev-parse --short HEAD) - name: Check outputs - run: echo ${{ steps.vars.outputs.sha_short }} + run: echo ${{ steps.sha_short.outputs.sha_short }} - name: Build if: success() env: - BUILD_VERSION: ${{ steps.version.outputs.SHA_SHORT }} + BUILD_VERSION: ${{ steps.sha_short.outputs.SHA_SHORT }} run: echo ${{ env.BUILD_VERSION }} #run: make build From 0083459d9f477a02f56351a3a2d97b11488127b7 Mon Sep 17 00:00:00 2001 From: Ido David Date: Mon, 9 Aug 2021 11:56:14 -0400 Subject: [PATCH 9/9] fix build version var in pr/master --- .github/workflows/master.yml | 5 ++--- .github/workflows/pr.yml | 5 +---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 31b6de35..f9f00b2e 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -29,11 +29,10 @@ jobs: - name: Create Short Commit Sha id: sha_short if: success() - run: | - echo ::set-output name=SHA_SHORT::$(git rev-parse --short HEAD) + run: echo ::set-output name=SHA_SHORT::$(git rev-parse --short HEAD) - name: Build if: success() env: - BUILD_VERSION: ${{ steps.version.outputs.SHA_SHORT }} + BUILD_VERSION: ${{ steps.sha_short.outputs.SHA_SHORT }} run: make build diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index badf42f6..8e59603a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -28,12 +28,9 @@ jobs: id: sha_short if: success() run: echo ::set-output name=SHA_SHORT::$(git rev-parse --short HEAD) - - name: Check outputs - run: echo ${{ steps.sha_short.outputs.sha_short }} - name: Build if: success() env: BUILD_VERSION: ${{ steps.sha_short.outputs.SHA_SHORT }} - run: echo ${{ env.BUILD_VERSION }} - #run: make build + run: make build