From df17d908d084fddd81bcc1ffe9c3d8939cbbe534 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Wed, 18 Nov 2026 15:35:17 -0700 Subject: [PATCH 1/3] add publish workflow --- .github/workflows/publish.yml | 132 ++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..84a08e4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,132 @@ +name: "Build and optionally release PyPi and docker packages" + +on: + workflow_dispatch: + pull_request: + push: + branches: + - "main" + tags: + - "v[0-9]+.[0-9]+.[0-9]+*" + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +env: + # Many color libraries just need this to be set to any value, but at least + # one distinguishes color depth, where "3" -> "256-bit color". + FORCE_COLOR: 3 + DOCKER_IMAGE_NAME: "dataone-auth" + # 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.ref_name if github.ref_type == 'tag' else 'latest' + # https://docs.github.com/en/actions/learn-github-actions/expressions + DOCKER_IMAGE_TAG: + "${{ github.ref_type == 'tag' && github.ref_name || 'latest' }}" + +jobs: + ####################################################################### + # Build Python + ####################################################################### + build-python: + name: "Build python distributions (wheel & sdist)" + runs-on: "ubuntu-latest" + + steps: + - uses: "actions/checkout@v7" + with: + fetch-depth: 0 + + - uses: "hynek/build-and-inspect-python-package@v3.0.1" + + ####################################################################### + # Build Docker + ####################################################################### + build-docker: + name: "Build docker container image" + runs-on: "ubuntu-latest" + steps: + - name: "Check out repository" + uses: "actions/checkout@v7" + + - name: "Build container image" + run: | + docker build --tag "ghcr.io/dataoneorg/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" . + docker save "ghcr.io/dataoneorg/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" -o docker-image.tar + - name: "Upload image tarball as artifact" + uses: "actions/upload-artifact@v7" + with: + name: "docker-image-tar" + path: "docker-image.tar" + + ####################################################################### + # Publish python + ####################################################################### + publish-python: + if: github.ref_type == 'tag' + # Only publish if both Python and Docker builds are successful. + needs: ["build-python", "build-docker"] + name: "Publish to PyPI" + environment: "pypi" + permissions: + id-token: "write" + runs-on: "ubuntu-latest" + + steps: + - uses: "actions/download-artifact@v8" + with: + name: "Packages" + path: "dist" + + - uses: "pypa/gh-action-pypi-publish@v1.14.2" + + ####################################################################### + # Publish Docker + ####################################################################### + publish-docker: + # Only push on tag or push to main. + if: github.ref_type == 'tag' || github.ref == 'refs/heads/main' + name: "Push docker container image" + runs-on: "ubuntu-latest" + # Only publish if both Python and Docker builds are successful. + needs: ["build-python", "build-docker"] + steps: + - name: "Download image tarball" + uses: "actions/download-artifact@v8" + with: + name: "docker-image-tar" + + - name: "Load Docker image" + run: "docker load -i docker-image.tar" + + - name: "GHCR login" + uses: "docker/login-action@v4" + with: + registry: "ghcr.io" + username: "${{ github.repository_owner }}" + password: "${{ secrets.GITHUB_TOKEN }}" + + - name: "Push to image registry (GHCR)" + run: | + # Push to GHCR + docker push "ghcr.io/dataoneorg/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" + + ####################################################################### + # GitHub release + ####################################################################### + publish-gh-release: + # Only publish a GH release when publish-python and publish-docker tasks are + # complete and the ref type is a tag (e.g,. v0.1.0). + if: github.ref_type == 'tag' + name: "Create GitHub release" + needs: ["publish-python", "publish-docker"] + runs-on: "ubuntu-latest" + steps: + - name: "Checkout" + uses: "actions/checkout@v7" + - name: "Release" + uses: "softprops/action-gh-release@v3" + with: + generate_release_notes: true From 0e274ffbd9b239e5e8129af3824175f92c528ab9 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Wed, 18 Nov 2026 15:37:42 -0700 Subject: [PATCH 2/3] simplify build --- .github/workflows/publish.yml | 69 ----------------------------------- 1 file changed, 69 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 84a08e4..445e169 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -41,26 +41,6 @@ jobs: - uses: "hynek/build-and-inspect-python-package@v3.0.1" - ####################################################################### - # Build Docker - ####################################################################### - build-docker: - name: "Build docker container image" - runs-on: "ubuntu-latest" - steps: - - name: "Check out repository" - uses: "actions/checkout@v7" - - - name: "Build container image" - run: | - docker build --tag "ghcr.io/dataoneorg/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" . - docker save "ghcr.io/dataoneorg/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" -o docker-image.tar - - name: "Upload image tarball as artifact" - uses: "actions/upload-artifact@v7" - with: - name: "docker-image-tar" - path: "docker-image.tar" - ####################################################################### # Publish python ####################################################################### @@ -81,52 +61,3 @@ jobs: path: "dist" - uses: "pypa/gh-action-pypi-publish@v1.14.2" - - ####################################################################### - # Publish Docker - ####################################################################### - publish-docker: - # Only push on tag or push to main. - if: github.ref_type == 'tag' || github.ref == 'refs/heads/main' - name: "Push docker container image" - runs-on: "ubuntu-latest" - # Only publish if both Python and Docker builds are successful. - needs: ["build-python", "build-docker"] - steps: - - name: "Download image tarball" - uses: "actions/download-artifact@v8" - with: - name: "docker-image-tar" - - - name: "Load Docker image" - run: "docker load -i docker-image.tar" - - - name: "GHCR login" - uses: "docker/login-action@v4" - with: - registry: "ghcr.io" - username: "${{ github.repository_owner }}" - password: "${{ secrets.GITHUB_TOKEN }}" - - - name: "Push to image registry (GHCR)" - run: | - # Push to GHCR - docker push "ghcr.io/dataoneorg/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" - - ####################################################################### - # GitHub release - ####################################################################### - publish-gh-release: - # Only publish a GH release when publish-python and publish-docker tasks are - # complete and the ref type is a tag (e.g,. v0.1.0). - if: github.ref_type == 'tag' - name: "Create GitHub release" - needs: ["publish-python", "publish-docker"] - runs-on: "ubuntu-latest" - steps: - - name: "Checkout" - uses: "actions/checkout@v7" - - name: "Release" - uses: "softprops/action-gh-release@v3" - with: - generate_release_notes: true From c1312869fc1bd0f52de4c95092e20d3d21a560c4 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Wed, 18 Nov 2026 15:43:11 -0700 Subject: [PATCH 3/3] fix deps --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 445e169..167ab04 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -47,7 +47,7 @@ jobs: publish-python: if: github.ref_type == 'tag' # Only publish if both Python and Docker builds are successful. - needs: ["build-python", "build-docker"] + needs: ["build-python"] name: "Publish to PyPI" environment: "pypi" permissions: