From 6b2c65769f212352267b7b9c1e4a8c53876522e7 Mon Sep 17 00:00:00 2001 From: Maartje Eyskens Date: Fri, 22 Nov 2024 12:49:43 +0100 Subject: [PATCH] Add CI action to release to GHCR Signed-off-by: Maartje Eyskens --- .github/workflows/docker.yml | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..b693ca1 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,56 @@ +name: ci +on: + push: + branches: + - main + release: + pull_request: #dev only, remove me!!! + + +jobs: + build-test: + name: build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install just + uses: taiki-e/install-action@just + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Create Kind Cluster + uses: helm/kind-action@v1 + with: + cluster_name: kind + - name: Install ko + uses: ko-build/setup-ko@v0.6 + env: + KO_DOCKER_REPO: kind.local + - name: Install dependencies + run: | + go mod download + - name: Run a ko build + run: just build + env: + KO_DOCKER_REPO: ghcr.io/cofide/cofidectl-debug-container + - name: Tag the image with the release tag + if: github.event_name == 'release' + run: | + docker tag ghcr.io/cofide/cofidectl-debug-container:latest ghcr.io/cofide/cofidectl-debug-container:${GITHUB_REF#refs/tags/} + - name: Tag the image with the commit hash + if: github.event_name != 'release' + run: | + docker tag ghcr.io/cofide/cofidectl-debug-container:latest ghcr.io/cofide/cofidectl-debug-container:${GITHUB_SHA} + - name: Login to GitHub Container Registry + run: | + echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u cofide --password-stdin + - name: Push the release tag + if: github.event_name == 'release' + run: | + docker push ghcr.io/cofide/cofidectl-debug-container:${GITHUB_REF#refs/tags/} + - name: Push the commit hash + if: github.event_name == 'release' + run: | + docker push ghcr.io/cofide/cofidectl-debug-container:${GITHUB_SHA}