From 61f48fa577662392bda680c99d2e4ec8e23642e9 Mon Sep 17 00:00:00 2001 From: Marc Sune Date: Sun, 25 Aug 2024 12:43:41 +0200 Subject: [PATCH] .github: merge ci.yaml and publish_docker.yaml Fix both workflows in a single yaml, such that dockerization doesn't happen if checks fail. --- .github/workflows/ci.yaml | 46 ++++++++++++++++++++++++ .github/workflows/publish_docker.yaml | 52 --------------------------- 2 files changed, 46 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/publish_docker.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1d743dc..f578b37 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,6 +7,12 @@ on: env: ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true +permissions: + packages: write + +env: + PLATFORMS: linux/amd64 + jobs: make_check: runs-on: ubuntu-22.04 @@ -37,3 +43,43 @@ jobs: - name: "Run tests..." run: cd sfunnel/test && make + + docker_build_and_publish: + needs: [make_check] + runs-on: ubuntu-22.04 + steps: + - name: "Checkout sfunnel" + uses: actions/checkout@v4 + with: + path: sfunnel + fetch-depth: 0 + fetch-tags: 1 + + - name: "Set up Docker buildx" + uses: docker/setup-buildx-action@v3 + + - name: "Login to GitHub Container Registry (ghcr.io)" + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{github.actor}} + password: ${{secrets.GITHUB_TOKEN}} + + - name: "Build and push to ghcr" + run: | + #Cross-build + cd sfunnel + + echo "Fix mess with tags in actions/checkout..." + git fetch -f && git fetch -f --tags + + export TAG=$(git describe HEAD | sed 's/-.*$//g' | tr -d "v") + EXACT_TAG=$(git describe --exact-match --match "v*" || echo "") + + if [[ "${EXACT_TAG}" != "" ]]; then + echo "Cross-building and PUSHING!" + docker buildx build --platform ${PLATFORMS} --push -f docker/Dockerfile . --tag ghcr.io/${GITHUB_REPOSITORY}:${TAG} + else + echo "Cross-building ONLY" + docker buildx build --platform ${PLATFORMS} -f docker/Dockerfile . + fi diff --git a/.github/workflows/publish_docker.yaml b/.github/workflows/publish_docker.yaml deleted file mode 100644 index c89a27a..0000000 --- a/.github/workflows/publish_docker.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: docker-publish-ghcr - -on: - workflow_dispatch: - push: - pull_request: - -permissions: - packages: write - -env: - PLATFORMS: linux/amd64 - -jobs: - docker_build_and_publish: - runs-on: ubuntu-22.04 - steps: - - name: "Checkout sfunnel" - uses: actions/checkout@v4 - with: - path: sfunnel - fetch-depth: 0 - fetch-tags: 1 - - - name: "Set up Docker buildx" - uses: docker/setup-buildx-action@v3 - - - name: "Login to GitHub Container Registry (ghcr.io)" - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{github.actor}} - password: ${{secrets.GITHUB_TOKEN}} - - - name: "Build and push to ghcr" - run: | - #Cross-build - cd sfunnel - - echo "Fix mess with tags in actions/checkout..." - git fetch -f && git fetch -f --tags - - export TAG=$(git describe HEAD | sed 's/-.*$//g' | tr -d "v") - EXACT_TAG=$(git describe --exact-match --match "v*" || echo "") - - if [[ "${EXACT_TAG}" != "" ]]; then - echo "Cross-building and PUSHING!" - docker buildx build --platform ${PLATFORMS} --push -f docker/Dockerfile . --tag ghcr.io/${GITHUB_REPOSITORY}:${TAG} - else - echo "Cross-building ONLY" - docker buildx build --platform ${PLATFORMS} -f docker/Dockerfile . - fi