From d04c1391baadbb857269be041f00f0e3c7f3bb27 Mon Sep 17 00:00:00 2001 From: masl Date: Thu, 19 Oct 2023 16:47:25 +0200 Subject: [PATCH] ci: add github workflow on push --- .github/workflows/push.yml | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..eaed0ef --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,63 @@ +name: docker-build-push +on: push +env: + REGISTRY: ghcr.io + +jobs: + test: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags') + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: 1.21 + - name: Run Quality Control Checks + run: make audit + + deploy: + runs-on: ubuntu-latest + needs: test + if: startsWith(github.ref, 'refs/tags') + steps: + - name: Extract Version + id: version_step + run: | + echo "##[set-output name=version;]VERSION=${GITHUB_REF#$"refs/tags/v"}" + echo "##[set-output name=version_tag;]$GITHUB_REPOSITORY:${GITHUB_REF#$"refs/tags/v"}" + echo "##[set-output name=latest_tag;]$GITHUB_REPOSITORY:latest" + + - name: Print Version + run: | + echo ${{steps.version_step.outputs.version_tag}} + echo ${{steps.version_step.outputs.latest_tag}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.CR_TOKEN }} + + - name: PrepareReg Names + id: read-docker-image-identifiers + run: | + echo VERSION_TAG=$(echo ${{ steps.version_step.outputs.version_tag }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV + echo LASTEST_TAG=$(echo ${{ steps.version_step.outputs.latest_tag }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.VERSION_TAG }} + ${{ env.REGISTRY }}/${{ env.LASTEST_TAG }} + build-args: | + ${{ steps.version_step.outputs.version }} \ No newline at end of file