From 2f1f5c34d137ef0c440bb21c63e4ce9807bd0260 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Thu, 3 Aug 2023 20:44:22 -0600 Subject: [PATCH 1/2] Use a re-usable workflow from org --- ...ainer-image-then-build-qgreenland-core.yml | 32 +++++ .github/workflows/test-and-build.yml | 124 ------------------ .github/workflows/test.yml | 71 ++++++++++ 3 files changed, 103 insertions(+), 124 deletions(-) create mode 100644 .github/workflows/build-and-publish-container-image-then-build-qgreenland-core.yml delete mode 100644 .github/workflows/test-and-build.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build-and-publish-container-image-then-build-qgreenland-core.yml b/.github/workflows/build-and-publish-container-image-then-build-qgreenland-core.yml new file mode 100644 index 00000000..0f19909b --- /dev/null +++ b/.github/workflows/build-and-publish-container-image-then-build-qgreenland-core.yml @@ -0,0 +1,32 @@ +name: "Build and publish container image, then (if tag) trigger QGreenland Core build" +# When a push to the default branch occurs, build and release a "latest" image +# When a tag `vX.Y.Z` push occurs, build and release an image with that tag + +on: + push: + branches: + - "main" + tags: + - "v[0-9]+.[0-9]+.[0-9]+*" + + +jobs: + + build-and-release-image: + uses: "nsidc/.github/.github/workflows/build-and-publish-container-image.yml@main" + secrets: "inherit" + + + build-package: + name: "Build QGreenland project (if tag)" + runs-on: "ubuntu-latest" + needs: ["build-and-release-image"] + if: "github.ref_type == 'tag'" + steps: + - name: "Trigger Jenkins to build QGreenland Core" + run: | + JOB_NAME="qgreenland_C3_Production_Build_QGreenland_Package" + JOB_URL="${{ secrets.JENKINS_URL }}/job/${JOB_NAME}" + JOB_BUILD_URL="${JOB_URL}/buildWithParameters?ref=${{ github.ref_name }}&delay=5sec" + + wget "$JOB_BUILD_URL" diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml deleted file mode 100644 index 2b94155a..00000000 --- a/.github/workflows/test-and-build.yml +++ /dev/null @@ -1,124 +0,0 @@ -name: "Test, release, and build" - -on: - # TODO: We currently get double workflows when pushing to pull request - # branches. Set this to only run on pushes to `main` and pull requests - # instead? - push: - branches: - - "main" - tags: - - "v[0-9]+.[0-9]+.[0-9]+*" - 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: "Apt install libgl1-mesa-glx" - run: | - # Install libgl1-mesa-glx. Import errors occur otherwise. - # See: https://app.circleci.com/jobs/github/nsidc/qgreenland/72/parallel-runs/0/steps/0-102 - sudo apt-get update - sudo apt-get install -y libgl1-mesa-glx - - - name: "Install Conda environment" - uses: "mamba-org/setup-micromamba@v1" - with: - environment-file: "environments/main/conda-lock.yml" - # When using a lock-file, we have to set an environment name. - environment-name: "qgreenland-ci" - cache-environment: true - # Increase this key to trigger cache invalidation - cache-environment-key: 1 - - - name: "Run tests" - run: "inv test.ci" - env: - # QGIS complains when setting up an QgsApplicatoin if `QT_QPA_PLATFORM` is not - # set to `offscreen`: - # qt.qpa.xcb: could not connect to display - # qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even - # though it was found. - # This application failed to start because no Qt - # platform plugin could be initialized. Reinstalling the application - # may fix this problem. - # - # Available platform plugins are: eglfs, minimal, minimalegl, - # offscreen, vnc, webgl, xcb. - # - # Fatal Python error: Aborted - QT_QPA_PLATFORM: offscreen - - - # 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: - name: "Build and (if `main` or tag) release container image" - runs-on: "ubuntu-latest" - needs: ["test"] - env: - IMAGE_NAME: "nsidc/qgreenland" - # 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: - # 'latest' if github.ref_type == 'branch' else github.ref_name - # https://docs.github.com/en/actions/learn-github-actions/expressions - 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 (if `main` or tag)" - if: "github.ref_type == 'tag' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch)" - uses: "docker/login-action@v2" - with: - username: "${{secrets.DOCKER_USER}}" - password: "${{secrets.DOCKER_PASS}}" - - - name: "GHCR login (if `main` or tag)" - if: "github.ref_type == 'tag' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch)" - uses: "docker/login-action@v2" - with: - registry: "ghcr.io" - username: "${{ github.repository_owner }}" - password: "${{ secrets.GITHUB_TOKEN }}" - - - name: "Release to DockerHub and GHCR (if `main` or tag)" - if: "github.ref_type == 'tag' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch)" - 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: - name: "Build QGreenland project (if tag)" - runs-on: "ubuntu-latest" - needs: ["build-and-release-image"] - if: "github.ref_type == 'tag'" - steps: - - name: "Trigger Jenkins to build QGreenland Core" - run: | - JOB_NAME="qgreenland_C3_Production_Build_QGreenland_Package" - JOB_URL="${{ secrets.JENKINS_URL }}/job/${JOB_NAME}" - JOB_BUILD_URL="${JOB_URL}/buildWithParameters?ref=${{ github.ref_name }}&delay=5sec" - - wget "$JOB_BUILD_URL" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..36b259ba --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,71 @@ +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: "Apt install libgl1-mesa-glx" + run: | + # Install libgl1-mesa-glx. Import errors occur otherwise. + # See: https://app.circleci.com/jobs/github/nsidc/qgreenland/72/parallel-runs/0/steps/0-102 + sudo apt-get update + sudo apt-get install -y libgl1-mesa-glx + + - name: "Install Conda environment" + uses: "mamba-org/setup-micromamba@v1" + with: + environment-file: "environments/main/conda-lock.yml" + # When using a lock-file, we have to set an environment name. + environment-name: "qgreenland-ci" + cache-environment: true + # Increase this key to trigger cache invalidation + cache-environment-key: 1 + + - name: "Run tests" + run: "inv test.ci" + env: + # QGIS complains when setting up an QgsApplicatoin if `QT_QPA_PLATFORM` is not + # set to `offscreen`: + # qt.qpa.xcb: could not connect to display + # qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even + # though it was found. + # This application failed to start because no Qt + # platform plugin could be initialized. Reinstalling the application + # may fix this problem. + # + # Available platform plugins are: eglfs, minimal, minimalegl, + # offscreen, vnc, webgl, xcb. + # + # Fatal Python error: Aborted + QT_QPA_PLATFORM: offscreen + + + test-build-container-image: + name: "Test container image build" + runs-on: "ubuntu-latest" + needs: ["test"] + steps: + - name: "Check out repository" + uses: "actions/checkout@v3" + + - name: "Build container image" + run: | + docker build . From 355e59cda176439bd28bca9346c5cdee62284986 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Thu, 3 Aug 2023 20:58:11 -0600 Subject: [PATCH 2/2] Limit test-builds of container image to pull requests --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 36b259ba..f3dcf635 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,6 +60,9 @@ jobs: test-build-container-image: name: "Test container image build" + # The build will happen for real on pushes to the main branch, so only do + # the test on PRs. + if: "github.event_name == 'pull_request'" runs-on: "ubuntu-latest" needs: ["test"] steps: