From 71710d45e7327dd955d21780153a415c7210ad09 Mon Sep 17 00:00:00 2001 From: "Serhii [boonya] Buinytskyi" <779184+boonya@users.noreply.github.com> Date: Sat, 18 Jun 2022 16:46:54 +0300 Subject: [PATCH] Workflow Release (#75) --- .github/workflows/build.yml | 18 +++++--- .github/workflows/release.yml | 42 ++++++++++++++++--- .../{verification.yml => verify.yml} | 3 +- 3 files changed, 51 insertions(+), 12 deletions(-) rename .github/workflows/{verification.yml => verify.yml} (98%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0f3c17..f217c2e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,7 @@ name: "Build and publish 🏭" on: + workflow_call: push: tags: - "*" @@ -13,7 +14,7 @@ env: jobs: bundle: - name: Build Meteor Bundle 📦 + name: Meteor Bundle 📦 runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 @@ -42,6 +43,11 @@ jobs: ) echo ${META} > meta.json + echo "meteor version: ${METEOR}" + echo "package version: ${VERSION}" + echo "hash: ${HASH}" + echo "bundle name: ${BUNDLE}" + - uses: meteorengineer/setup-meteor@v1 with: meteor-release: ${{ steps.meta.outputs.meteor }} @@ -70,7 +76,7 @@ jobs: if-no-files-found: error docker: - name: Build Docker Image 🐳 + name: Docker Image 🐳 runs-on: ubuntu-20.04 needs: [bundle] steps: @@ -88,11 +94,13 @@ jobs: HASH=$(cat meta.json | jq -r '.hash') TAGS="${{ env.GHCR_IMAGE }}:${HASH},${{ env.GHCR_IMAGE }}:${GITHUB_REF_NAME}" - if [[ $GITHUB_REF == ref/head/main ]]; then - TAGS="${TAGS},${{ env.GHCR_IMAGE }}:${VERSION}" - fi echo ::set-output name=tags::${TAGS} + echo "package version: ${VERSION}" + echo "bundle name: ${BUNDLE}" + echo "hash: ${HASH}" + echo "tags: ${TAGS}" + - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c17add0..3900d39 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,9 +9,34 @@ env: DOCKER_HUB_IMAGE: "${{ github.repository }}" jobs: + version: + name: Compare tag and package version + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - name: "Check" + run: | + VERSION=$(cat package.json | jq -r '.version') + if [[ ${GITHUB_REF_NAME} != ${VERSION} ]]; + then + echo "Tag (${GITHUB_REF_NAME}) and package version (${VERSION}) are different." + echo "Something went wrong." + exit 1 + fi + + verify: + needs: [version] + uses: ./.github/workflows/verify.yml + + build: + needs: [verify, version] + uses: ./.github/workflows/build.yml + secrets: inherit + release: name: Copy Images from GHCR to DockerHub runs-on: ubuntu-20.04 + needs: [build] steps: - name: Login to DockerHub uses: docker/login-action@v2 @@ -26,11 +51,16 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GHCR_TOKEN_RW }} + - name: Prepare source and targets + id: meta + run: | + SRC="${{ env.GHCR_IMAGE }}:${GITHUB_REF_NAME}" + echo ::set-output name=src::${SRC} + DST="${{ env.GHCR_IMAGE }}:${GITHUB_REF_NAME},${{ env.GHCR_IMAGE }}:latest,${{ env.DOCKER_HUB_IMAGE }}:${GITHUB_REF_NAME},${{ env.DOCKER_HUB_IMAGE }}:latest" + echo ::set-output name=dst::${DST} + - name: Push Image - uses: akhilerm/tag-push-action@v2 + uses: akhilerm/tag-push-action@v2.0.0 with: - src: "${{ env.GHCR_IMAGE }}:${GITHUB_REF_NAME}" - dst: | - "${{ env.DOCKER_HUB_IMAGE }}:latest" - "${{ env.DOCKER_HUB_IMAGE }}:${GITHUB_REF_NAME}" - "${{ env.GHCR_IMAGE }}:latest" + src: ${{ steps.meta.outputs.src }} + dst: ${{ steps.meta.outputs.dst }} diff --git a/.github/workflows/verification.yml b/.github/workflows/verify.yml similarity index 98% rename from .github/workflows/verification.yml rename to .github/workflows/verify.yml index 31b5f09..7cf6900 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verify.yml @@ -1,6 +1,7 @@ name: "Verification 👮🏽‍♂️" on: + workflow_call: push: tags-ignore: ["*"] paths-ignore: ["**.md", "LICENSE"] @@ -10,7 +11,7 @@ on: jobs: versions: - name: Verify versions + name: Versions runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3