From 1613387dc7f3b9fe13d4d0d0b32de78f541a4e30 Mon Sep 17 00:00:00 2001 From: Jared Atkinson Date: Wed, 18 Nov 2026 21:35:25 -0800 Subject: [PATCH] fix: BED-10623 publish artifacts from published releases --- .github/workflows/publish-container.yml | 155 ------------------------ .github/workflows/publish.yml | 78 +++++------- .github/workflows/release-on-merge.yml | 107 ---------------- .github/workflows/test.yml | 30 +++++ README.md | 24 ++-- 5 files changed, 77 insertions(+), 317 deletions(-) delete mode 100644 .github/workflows/publish-container.yml delete mode 100644 .github/workflows/release-on-merge.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/publish-container.yml b/.github/workflows/publish-container.yml deleted file mode 100644 index 39d925a3..00000000 --- a/.github/workflows/publish-container.yml +++ /dev/null @@ -1,155 +0,0 @@ -name: Build and publish container - -on: - workflow_call: - inputs: - tag: - description: Existing release tag to build - required: true - type: string - -permissions: - contents: read - packages: write - -concurrency: - group: container-${{ inputs.tag }} - cancel-in-progress: false - -jobs: - publish: - if: >- - github.repository == 'SpecterOps/openhound-github' && - github.event_name == 'pull_request' && - github.event.action == 'closed' && - github.event.pull_request.merged == true && - github.event.pull_request.base.ref == 'main' - runs-on: ubuntu-latest - strategy: - matrix: - target: [cli, enterprise] - steps: - - name: Validate release tag - env: - RELEASE_TAG: ${{ inputs.tag }} - run: | - [[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { - echo "Expected a release tag such as v0.20.0" >&2 - exit 1 - } - - - name: Checkout release - uses: actions/checkout@v4 - with: - ref: refs/tags/${{ inputs.tag }} - - - name: Set image metadata - id: image - env: - RELEASE_TAG: ${{ inputs.tag }} - REPOSITORY: ${{ github.repository }} - TARGET: ${{ matrix.target }} - run: | - VERSION=${RELEASE_TAG#v} - IMAGE="ghcr.io/${REPOSITORY,,}" - SUFFIX="" - if [[ "$TARGET" == cli ]]; then SUFFIX="-cli"; fi - echo "version=$VERSION" >> "$GITHUB_OUTPUT" - echo "tag=$IMAGE:$VERSION$SUFFIX" >> "$GITHUB_OUTPUT" - echo "latest_tag=$IMAGE:latest$SUFFIX" >> "$GITHUB_OUTPUT" - - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Build smoke-test image - uses: docker/build-push-action@v7 - with: - context: . - target: ${{ matrix.target }} - platforms: linux/amd64 - load: true - tags: openhound-github:smoke - build-args: | - COLLECTOR_VERSION=${{ steps.image.outputs.version }} - cache-from: type=gha,scope=${{ matrix.target }} - - - name: Verify runtime and installed collector - env: - EXPECTED_VERSION: ${{ steps.image.outputs.version }} - run: | - docker run --rm --entrypoint python -e EXPECTED_VERSION openhound-github:smoke -c ' - import importlib.metadata as metadata - import os - import runpy - from unittest.mock import patch - import openhound_github.main - assert os.getuid() != 0 - assert metadata.version("openhound-github") == os.environ["EXPECTED_VERSION"] - entries = metadata.entry_points(group="openhound.sources") - assert any(entry.name == "github" and entry.load() for entry in entries) - with patch.dict(os.environ, { - "DESTINATION__BLOODHOUNDENTERPRISE__URL": "https://example.invalid", - "DESTINATION__BLOODHOUNDENTERPRISE__TOKEN_ID": "smoke-test-id", - "DESTINATION__BLOODHOUNDENTERPRISE__TOKEN_KEY": "smoke-test-key", - }), patch("openhound.scheduler.service.Service", autospec=True) as service: - runpy.run_path("/app/src/scheduler.py", run_name="__main__") - assert service.call_args.kwargs["collector_name"] == "github" - service.return_value.start.assert_called_once_with() - ' - - - name: Verify CLI - if: matrix.target == 'cli' - run: docker run --rm openhound-github:smoke --help - - - name: Log in to GHCR - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push multi-architecture image - uses: docker/build-push-action@v7 - with: - context: . - target: ${{ matrix.target }} - platforms: linux/amd64,linux/arm64 - push: true - sbom: true - tags: ${{ steps.image.outputs.tag }} - labels: | - org.opencontainers.image.source=https://github.com/${{ github.repository }} - org.opencontainers.image.version=${{ steps.image.outputs.version }} - build-args: | - COLLECTOR_VERSION=${{ steps.image.outputs.version }} - cache-from: type=gha,scope=${{ matrix.target }} - - - name: Update latest alias for newest release - env: - RELEASE_TAG: ${{ inputs.tag }} - VERSIONED_TAG: ${{ steps.image.outputs.tag }} - LATEST_TAG: ${{ steps.image.outputs.latest_tag }} - run: | - NEWEST_RELEASE_TAG=$( - git ls-remote --refs --tags origin 'refs/tags/v*' | - awk '$2 ~ /^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+$/ { - sub("^refs/tags/", "", $2) - print $2 - }' | - sort -V | - tail -n 1 - ) - if [[ -z "$NEWEST_RELEASE_TAG" ]]; then - echo "Unable to determine the newest release tag" >&2 - exit 1 - fi - if [[ "$RELEASE_TAG" != "$NEWEST_RELEASE_TAG" ]]; then - echo "Skipping $LATEST_TAG: newest release is $NEWEST_RELEASE_TAG" - exit 0 - fi - docker buildx imagetools create \ - --tag "$LATEST_TAG" \ - "$VERSIONED_TAG" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1d7ab193..133fce32 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,63 +1,47 @@ -name: Build and Publish +name: Publish release on: - push: - tags: - - "v*" - workflow_call: - inputs: - tag: - description: "Tag to build and publish" - required: true - type: string - + release: + types: [published] permissions: contents: read jobs: - build: + test: + uses: ./.github/workflows/test.yml + with: + tag: ${{ github.event.release.tag_name }} + + build-python: + needs: test + uses: SpecterOps/openhound-workflows/.github/workflows/build-python.yml@5c902e58782c9552e2d36950dc743e9237ca4356 + with: + tag: ${{ github.event.release.tag_name }} + python-version: '3.13' + + publish-python: + needs: build-python + runs-on: ubuntu-latest + environment: pypi permissions: contents: read id-token: write - environment: pypi - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ inputs.tag && format('refs/tags/{0}', inputs.tag) || github.ref }} # using input tags or github ref if tags are manually pushed - fetch-depth: 0 - - - name: Set up Python - uses: actions/setup-python@v5 + - uses: actions/download-artifact@v4 with: - python-version: "3.13" - - - name: Install uv - uses: astral-sh/setup-uv@v7 - - - name: Create virtual environment - run: uv venv .venv - - - name: Build package - run: uv build - - - name: Publish package - run: uv publish - - container: - needs: build + name: python-distributions + path: dist/ + - uses: astral-sh/setup-uv@v7 + - name: Publish distributions to PyPI + run: uv publish --trusted-publishing always dist/* + + publish-container: + needs: publish-python permissions: contents: read packages: write - if: >- - github.repository == 'SpecterOps/openhound-github' && - github.event_name == 'pull_request' && - github.event.action == 'closed' && - github.event.pull_request.merged == true && - github.event.pull_request.base.ref == 'main' - uses: ./.github/workflows/publish-container.yml + uses: SpecterOps/openhound-workflows/.github/workflows/publish-container.yml@bd6b59e0018dc3b3326858e4a8baa5b7ebf6efe5 with: - tag: ${{ inputs.tag || github.ref_name }} + tag: ${{ github.event.release.tag_name }} + prerelease: ${{ github.event.release.prerelease }} diff --git a/.github/workflows/release-on-merge.yml b/.github/workflows/release-on-merge.yml deleted file mode 100644 index af8e864e..00000000 --- a/.github/workflows/release-on-merge.yml +++ /dev/null @@ -1,107 +0,0 @@ -name: Create Release Tag and publish new version - -on: - pull_request: - branches: - - main - types: - - closed - paths: - - "src/**" - - "pyproject.toml" - - "uv.lock" - - "README.md" - - "Dockerfile" - - ".dockerignore" - - ".github/workflows/publish.yml" - - ".github/workflows/publish-container.yml" - -permissions: - contents: write - id-token: write # This is required for requesting the JWT for the OIDC provider - packages: write - -concurrency: - group: release-main - queue: max - cancel-in-progress: false - -jobs: - - # TODO: Re-enable tests when pushed - # test-core: - # if: github.event.pull_request.merged == true - # uses: ./.github/workflows/test.yml - # secrets: inherit - - tag-release: - # needs: test-core - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - outputs: - new_version: ${{ steps.versioning.outputs.new_version }} - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.event.pull_request.merge_commit_sha }} - - - name: Fetch tags - run: git fetch --tags - - - name: Determine next version - id: versioning - env: - BRANCH_NAME: ${{ github.event.pull_request.head.ref }} - run: | - # Get latest tag or fallback - LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) - if [ -z "$LATEST_TAG" ]; then - LATEST_TAG="v0.0.0" - fi - - echo "Latest tag: $LATEST_TAG" - - VERSION=${LATEST_TAG#v} - IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" - - echo "Merged branch: $BRANCH_NAME" - - if [[ "$BRANCH_NAME" == fix/* || "$BRANCH_NAME" == patch/* || "$BRANCH_NAME" == chore/* ]]; then - PATCH=$((PATCH + 1)) - elif [[ "$BRANCH_NAME" == feature/* || "$BRANCH_NAME" == minor/* ]]; then - MINOR=$((MINOR + 1)) - PATCH=0 - elif [[ "$BRANCH_NAME" == major/* ]]; then - MAJOR=$((MAJOR + 1)) - MINOR=0 - PATCH=0 - else - echo "Branch does not trigger release." - exit 0 - fi - - NEW_VERSION="v$MAJOR.$MINOR.$PATCH" - - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT - echo "Next version: $NEW_VERSION" - - - name: Create and push tag - if: env.NEW_VERSION != '' - run: | - git config user.name "github-actions" - git config user.email "github-actions@github.com" - - git tag $NEW_VERSION - git push origin $NEW_VERSION - - publish: - needs: tag-release - if: needs.tag-release.outputs.new_version != '' - uses: ./.github/workflows/publish.yml - with: - tag: ${{ needs.tag-release.outputs.new_version }} - secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..c15af73e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Test release + +on: + workflow_call: + inputs: + tag: + description: Existing release tag to test + required: true + type: string + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: refs/tags/${{ inputs.tag }} + fetch-depth: 0 + persist-credentials: false + - uses: actions/setup-python@v5 + with: + python-version: '3.13' + - uses: astral-sh/setup-uv@v7 + - name: Install locked development dependencies + run: uv sync --frozen --group dev + - name: Run tests + run: uv run --no-sync pytest -q diff --git a/README.md b/README.md index 44a1c656..8bfebb2f 100644 --- a/README.md +++ b/README.md @@ -287,11 +287,10 @@ Follow the OpenHound GitHub collector docs to get started: ## Container images -After a release-triggering pull request merges into `main` in -`SpecterOps/openhound-github`, the release workflow publishes the PyPI package -first, then builds images for `linux/amd64` and `linux/arm64` in GitHub Container -Registry. Container builds are skipped for forks, other branches, and standalone -tag pushes. Both images use the same release version: +Publishing a GitHub Release runs tests against its tag, builds and publishes the +PyPI package, then builds images for `linux/amd64` and `linux/arm64` in GitHub +Container Registry. Merging PRs and pushing tags do not publish artifacts. +Both images use the same release version: - `ghcr.io/specterops/openhound-github:` starts the BloodHound Enterprise scheduler. - `ghcr.io/specterops/openhound-github:-cli` runs the OpenHound CLI. @@ -300,8 +299,9 @@ For example, release tag `v0.20.0` produces image tags `0.20.0` and `0.20.0-cli` Use a version containing the container files; releases predating this workflow cannot be built without backporting those files. -Each release also updates `latest` for the scheduler and `latest-cli` for the -CLI. These aliases point to the same images as that release's versioned tags. +The newest published stable version updates `latest` for the scheduler and +`latest-cli` for the CLI. Prereleases and older stable versions do not move these +aliases. These aliases point to the same images as the selected release's versioned tags. Use versioned tags to pin a deployment. To update a Compose deployment using `latest`, run `docker compose pull` followed by `docker compose up -d`. @@ -344,6 +344,14 @@ docker run --rm ghcr.io/specterops/openhound-github:-cli --help ### Build and publish +Maintainers can merge several PRs before releasing. In GitHub, create a draft +release, choose a version tag (for example `v0.25.0`), and target the intended +commit on `main`. Review the included changes, then publish the release to start +the workflow. Draft releases do not publish packages or images. For a prerelease, +use a tag such as `v0.25.0rc1` and mark the GitHub Release as a prerelease; only +versioned image tags are published. Branch name prefixes no longer select or +increment release versions. + To build locally without publishing: ```sh @@ -372,7 +380,7 @@ already exists, grant this repository's Actions workflows write access to it. Breaking graph-model change, accompanied by OpenGraph schema `v1.5.0` (previously `v1.4.3`). Deploy the updated schema, saved searches, and collector -together. The `feature/` release workflow selects a minor collector release; +together. Select an appropriate collector release version when publishing; the collector package version is generated from the release tag. Enterprise teams use one native `ET_` node ID across all assigned organizations.