From 453b57e91136673bcea8f9675cd366c3dbdcdd26 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Mon, 10 Jul 2023 20:36:50 -0600 Subject: [PATCH] Add container image build and release job to GHA --- .github/workflows/test-and-build.yml | 44 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml index 04791f53..d8aca246 100644 --- a/.github/workflows/test-and-build.yml +++ b/.github/workflows/test-and-build.yml @@ -6,7 +6,7 @@ on: # instead? push: branches: - - "*" + - "main" tags: - "v[0-9]+.[0-9]+.[0-9]+*" pull_request: @@ -36,7 +36,6 @@ jobs: - name: "Install Conda environment" uses: "mamba-org/setup-micromamba@v1" with: - micromamba-version: "1.4.2-2" environment-file: "conda-lock.yml" # When using a lock-file, we have to set an environment name. environment-name: "qgreenland-ci" @@ -63,9 +62,48 @@ jobs: QT_QPA_PLATFORM: offscreen - build: + # TODO: Consider extracting everything below this line to a separate workflow + # which is triggered by pushes to the default branch and GitHub releases. + build-and-release-image: runs-on: "ubuntu-latest" needs: ["test"] + # if: "github.ref_type == 'tag' || github.ref == github.event.repository.default_branch" + if: "github.ref_type == 'tag' || github.ref_type == 'branch'" + env: + IMAGE_NAME: "nsidc/qgreenland" + IMAGE_TAG: "${{ github.ref_type == 'branch' && 'latest' || github.ref_name }}" + steps: + - name: "Check out repository" + uses: "actions/checkout@v3" + + - name: "Build Docker image" + run: | + docker build -t "${IMAGE_NAME}:${IMAGE_TAG}" . + + - name: "DockerHub login" + uses: "docker/login-action@v2" + with: + username: "${{secrets.DOCKER_USER}}" + password: "${{secrets.DOCKER_PASS}}" + + - name: "GHCR login" + uses: "docker/login-action@v2" + with: + registry: "ghcr.io" + username: "${{ github.repository_owner }}" + password: "${{ secrets.GITHUB_TOKEN }}" + + - name: "Release to DockerHub and GHCR" + run: | + docker push "${IMAGE_NAME}:${IMAGE_TAG}" + + docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "ghcr.io/${IMAGE_NAME}:${IMAGE_TAG}" + docker push "ghcr.io/${IMAGE_NAME}:${IMAGE_TAG}" + + + build-package: + runs-on: "ubuntu-latest" + needs: ["build-and-release-image"] if: "github.ref_type == 'tag'" steps: - name: "Trigger Jenkins to build QGreenland Core"