diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml new file mode 100644 index 00000000..f9f00b2e --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,38 @@ + +# build the image on master + +name: Master + +on: + push: + branches: + - master + 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: Build + if: success() + env: + BUILD_VERSION: ${{ steps.sha_short.outputs.SHA_SHORT }} + run: make build diff --git a/.github/workflows/pr_master.yml b/.github/workflows/pr.yml similarity index 66% rename from .github/workflows/pr_master.yml rename to .github/workflows/pr.yml index d84e939f..8e59603a 100644 --- a/.github/workflows/pr_master.yml +++ b/.github/workflows/pr.yml @@ -1,21 +1,16 @@ -# build the image on PRs and master +# build the image on PRs name: PR on: pull_request: - push: - branches: - - master paths-ignore: - 'README.md' jobs: build: runs-on: ubuntu-latest - env: - COMMIT_HASH: ${{ github.sha }} steps: - uses: actions/checkout@v2 with: @@ -29,7 +24,13 @@ jobs: 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: Build + if: success() env: - BUILD_VERSION: ${{ env.COMMIT_HASH }} + BUILD_VERSION: ${{ steps.sha_short.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/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 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}}"