diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e6136bca..df3629dd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,12 @@ name: Release # Required repo secrets (Settings -> Secrets and variables -> Actions): # PYPI_API_TOKEN - PyPI account -> API tokens # NPM_TOKEN - npmjs.com account -> Access Tokens -> Automation -# GITHUB_TOKEN (GHCR push) is provided automatically, no setup needed. +# GITHUB_TOKEN (GHCR push) is provided automatically, no setup needed. It +# can only push under this repo's own owner, so the image is +# ghcr.io//secfoo (ghcr.io/secfoo-com/secfoo on the public repo). +# +# Every publish step skips a version that's already out, so a run that +# failed halfway can simply be re-run for the same tag. on: workflow_dispatch: @@ -52,7 +57,7 @@ jobs: fail-fast: false matrix: include: - - os: macos-14 + - os: macos-15 name: darwin-arm64 - os: macos-15-intel name: darwin-x64 @@ -96,7 +101,16 @@ jobs: permissions: contents: write steps: - - uses: actions/download-artifact@v4 + # The binaries are 100+ MB each and this download has failed + # transiently before ("Artifact download failed after 5 retries"), + # so give it one more attempt before failing the release. + - id: download + uses: actions/download-artifact@v4 + continue-on-error: true + with: + path: artifacts + - if: steps.download.outcome == 'failure' + uses: actions/download-artifact@v4 with: path: artifacts - name: Flatten artifacts and compute checksums @@ -126,14 +140,18 @@ jobs: - env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: twine upload dist/*.tar.gz dist/*.whl + run: twine upload --skip-existing dist/*.tar.gz dist/*.whl publish-npm: name: Publish npm packages - needs: [check-version, release] + # Needs only the binaries, not the GitHub Release, so a flaky release + # upload doesn't also block npm. + needs: [check-version, build-binaries] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.tag }} - uses: actions/download-artifact@v4 with: path: artifacts @@ -147,6 +165,19 @@ jobs: VERSION: ${{ needs.check-version.outputs.version }} run: | set -euo pipefail + if [ -z "${NODE_AUTH_TOKEN:-}" ]; then + echo "::error::NPM_TOKEN secret is not set (Settings -> Secrets and variables -> Actions)." + exit 1 + fi + publish() { + local dir="$1" name + name=$(node -p "require('./$dir/package.json').name") + if npm view "$name@$VERSION" version >/dev/null 2>&1; then + echo "$name@$VERSION is already on npm, skipping" + else + npm publish --access public "$dir" + fi + } declare -A DIRS=( [darwin-arm64]=npm/secfoo-darwin-arm64 [darwin-x64]=npm/secfoo-darwin-x64 @@ -164,10 +195,10 @@ jobs: chmod +x "$pkgdir/bin/secfoo" fi npm version "$VERSION" --no-git-tag-version --prefix "$pkgdir" --allow-same-version - npm publish --access public "$pkgdir" + publish "$pkgdir" done npm version "$VERSION" --no-git-tag-version --prefix npm/secfoo --allow-same-version - npm publish --access public npm/secfoo + publish npm/secfoo publish-docker: name: Publish Docker image (GHCR) @@ -185,12 +216,37 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Image name (GHCR needs a lowercase owner) + id: image + run: echo "name=ghcr.io/$(echo "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')/secfoo" >> "$GITHUB_OUTPUT" - name: Wait for the new version to be installable from PyPI - run: sleep 60 + env: + VERSION: ${{ needs.check-version.outputs.version }} + run: | + for _ in $(seq 1 40); do + if pip download --no-deps --quiet --dest /tmp/pypi-check "secfoo==$VERSION" 2>/dev/null; then + exit 0 + fi + sleep 15 + done + echo "::error::secfoo==$VERSION is still not installable from PyPI after 10 minutes." + exit 1 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 - uses: docker/build-push-action@v6 with: context: . push: true + platforms: linux/amd64,linux/arm64 + build-args: | + SECFOO_VERSION=${{ needs.check-version.outputs.version }} + # The source label links the package to this repo, which is what + # lists it under the repo's "Packages" sidebar. + labels: | + org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} + org.opencontainers.image.version=${{ needs.check-version.outputs.version }} + org.opencontainers.image.licenses=MIT + org.opencontainers.image.description=Secfoo CLI: context-based security assessment with your coding agent tags: | - ghcr.io/rakfortltd/secfoo:${{ needs.check-version.outputs.version }} - ghcr.io/rakfortltd/secfoo:latest + ${{ steps.image.outputs.name }}:${{ needs.check-version.outputs.version }} + ${{ steps.image.outputs.name }}:latest diff --git a/src/secfoo/__about__.py b/src/secfoo/__about__.py index 493f7415..260c070a 100644 --- a/src/secfoo/__about__.py +++ b/src/secfoo/__about__.py @@ -1 +1 @@ -__version__ = "0.3.0" +__version__ = "0.3.1"