From 4b0f46918b7b9f0b9ca98caec401d07c752f98c3 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Wed, 26 Jul 2023 10:54:02 -0600 Subject: [PATCH 1/2] Add new GitHub Actions test and build steps --- .github/workflows/release.yml | 61 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 52 +++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..32a0e396 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +name: "Build and release container image" + +on: + push: + branches: + - "main" + release: + types: + - "published" + + +# Default to bash in login mode for all steps; key to activating conda +# environment! +# https://github.com/mamba-org/provision-with-micromamba#IMPORTANT +defaults: + run: + shell: "bash -l {0}" + + + +jobs: + + build-and-release-image: + name: "Build and release container image" + runs-on: "ubuntu-latest" + needs: ["test"] + env: + IMAGE_NAME: "nsidc/usaon-vta-survey" + # GitHub Actions expressions don't have great conditional support, so + # writing a ternary expression looks a lot like bash. In Python, this + # would read as: + # github.release.tag_name if github.event_name == 'release' else 'latest' + # https://docs.github.com/en/actions/learn-github-actions/expressions + IMAGE_TAG: "${{ github.event_name == 'release' && github.release.tag_name || 'latest' }}" + steps: + - name: "Check out repository" + uses: "actions/checkout@v3" + + - name: "Build container 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: "Push 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}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..7a64ecdc --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,52 @@ +name: "Test" + +on: + push: + branches: + - "main" + pull_request: + + +# Default to bash in login mode; key to activating conda environment +# https://github.com/mamba-org/provision-with-micromamba#IMPORTANT +defaults: + run: + shell: "bash -l {0}" + + +jobs: + test: + name: "Run tests" + runs-on: "ubuntu-latest" + steps: + - name: "Check out repository" + uses: "actions/checkout@v3" + + - name: "Install Conda environment" + uses: "mamba-org/setup-micromamba@v1" + with: + environment-file: "conda-lock.yml" + # When using a lock-file, we have to set an environment name. + environment-name: "usaon-vta-survey-ci" + cache-environment: true + # Increase this key to trigger cache invalidation + cache-environment-key: 0 + + - name: "Run pre-commit checks" + run: "pre-commit run --all-files --show-diff-on-failure --color always" + + - name: "Run tests" + run: "inv test" + + + test-build: + name: "Run test-build of container image" + runs-on: "ubuntu-latest" + needs: ["test"] + steps: + - name: "Check out repository" + uses: "actions/checkout@v3" + + - name: "Test-build container image" + run: | + docker build . From 9162d2b56dc9518ba41ffb7bdfd61281c8f4b931 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Wed, 26 Jul 2023 11:18:58 -0600 Subject: [PATCH 2/2] Remove CircleCI config --- .circleci/config.yml | 97 -------------------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index de1a7a48..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,97 +0,0 @@ -version: 2.0 - -setup: &setup - docker: - - image: continuumio/miniconda3:4.10.3 - working_directory: ~/usaon-vta-survey - -jobs: - test: - <<: *setup - steps: - - checkout - - restore_cache: - key: 'conda-{{ checksum "conda-lock.yml" }}' - - run: - name: "Create conda environment" - command: | - if [ -d "/opt/conda/envs/sipn-reanalysis-ingest" ]; then - echo "Environment exists in cache. Skipping build!" - exit 0 - fi - conda init bash - conda install --channel=conda-forge --name=base conda-lock - - conda-lock install -n usaon-vta-survey - - save_cache: - key: 'conda-{{ checksum "conda-lock.yml" }}' - paths: "/opt/conda" - - - run: - name: "Run pre-commit checks (lint, format)" - command: | - /bin/bash --login -c "conda activate usaon-vta-survey && pre-commit run --all-files --show-diff-on-failure --color always" - - - run: - name: 'Run all tests (lint, config validation, etc.)' - command: | - /bin/bash --login -c "conda activate usaon-vta-survey && inv test" - - # release: - # <<: *setup - # docker: - # - image: docker:20.10.3-git - # steps: - # - checkout - # # `setup_remote_docker` defaults to 17.09.0... - # # https://support.circleci.com/hc/en-us/articles/360050934711 - # # https://discuss.circleci.com/t/docker-build-fails-with-nonsensical-eperm-operation-not-permitted-copyfile/37364 - # - setup_remote_docker: - # version: 20.10.2 - # - run: - # name: Build and push Docker image - # command: | - # IMAGE_NAME="nsidc/usaon-vta-survey" - # echo "\$CIRCLE_TAG: ${CIRCLE_TAG}" - # echo "\$CIRCLE_BRANCH: ${CIRCLE_BRANCH}" - - # if [[ "${CIRCLE_TAG}" ]]; then - # TAG=${CIRCLE_TAG} - # elif [[ "${CIRCLE_BRANCH}" = "main" ]]; then - # TAG="latest" - # else - # # We don't really want images named after tags cluttering up our - # # DH repo, so we use workflow filters to prevent this job from - # # being triggered on a branch. Change the filters if we change - # # our mind. - # TAG=${CIRCLE_BRANCH} - # fi - - # echo "\$TAG: ${TAG}" - # DOCKER_IMAGE="${IMAGE_NAME}:${TAG}" - # docker build -t ${DOCKER_IMAGE} . - # echo "Built: ${DOCKER_IMAGE}" - # docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} - # docker push "${DOCKER_IMAGE}" - -workflows: - version: 2 - - # For commits on any branch, only run tests. - # For main branch, do a docker build. - # For tags vX.Y.Z*, do a docker build and push. - test-and-sometimes-release: - jobs: - - test: - filters: - tags: - only: /.*/ - #- release: - # context: org-global - # requires: - # - test - # filters: - # branches: - # only: main - # tags: - # only: /^v[0-9]+(\.[0-9]+)*(\.[\-a-zA-Z0-9]+)?$/