diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 70b55df..3be63e6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,7 +15,7 @@ on: jobs: check: - if: github.repository == 'ultralytics/mkdocs' && github.actor == 'glenn-jocher' + if: github.repository == 'ultralytics/mkdocs' && github.actor == 'glenn-jocher' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest permissions: contents: write @@ -32,13 +32,17 @@ jobs: - run: uv pip install --system --no-cache ultralytics-actions - id: check_pypi shell: python + env: + PYPI_DISPATCH: ${{ github.event.inputs.pypi }} run: | import os from actions.utils import check_pypi_version local_version, online_version, publish = check_pypi_version() + publish = publish or os.environ.get("PYPI_DISPATCH") == "true" # manual recovery re-run os.system(f'echo "increment={publish}" >> $GITHUB_OUTPUT') os.system(f'echo "current_tag=v{local_version}" >> $GITHUB_OUTPUT') - os.system(f'echo "previous_tag=v{online_version}" >> $GITHUB_OUTPUT') + if online_version != local_version: # empty on recovery re-runs so summarize falls back to the true previous tag + os.system(f'echo "previous_tag=v{online_version}" >> $GITHUB_OUTPUT') if publish: print('Ready to publish new version to PyPI ✅.') - name: Tag and Release @@ -49,11 +53,16 @@ jobs: PREVIOUS_TAG: ${{ steps.check_pypi.outputs.previous_tag }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} run: | - git config --global user.name "UltralyticsAssistant" - git config --global user.email "web@ultralytics.com" - git tag -a "$CURRENT_TAG" -m "$(git log -1 --pretty=%B)" - git push origin "$CURRENT_TAG" - ultralytics-actions-summarize-release + if [ -z "$(git ls-remote --tags origin "refs/tags/$CURRENT_TAG")" ]; then + git config --global user.name "UltralyticsAssistant" + git config --global user.email "web@ultralytics.com" + git tag -a "$CURRENT_TAG" -m "$(git log -1 --pretty=%B)" + git push origin "$CURRENT_TAG" + fi + if ! gh release view "$CURRENT_TAG" >/dev/null 2>&1; then + [ -n "$PREVIOUS_TAG" ] || git fetch --unshallow --tags # summarize resolves the previous tag from git history + ultralytics-actions-summarize-release + fi uv cache prune --ci build: @@ -91,6 +100,8 @@ jobs: name: dist path: dist/ - uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true # tolerate recovery re-runs after partial failures sbom: needs: [check, build, publish] @@ -114,12 +125,12 @@ jobs: format: spdx-json output-file: sbom.spdx.json path: sbom-env - - run: gh release upload ${{ needs.check.outputs.current_tag }} sbom.spdx.json + - run: gh release upload ${{ needs.check.outputs.current_tag }} sbom.spdx.json --clobber env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} notify: - needs: [check, publish] + needs: [check, publish, sbom] if: always() && needs.check.outputs.increment == 'True' runs-on: ubuntu-latest permissions: @@ -136,7 +147,7 @@ jobs: TITLE=$(printf '%s' "$TITLE" | sed -E "s@#([0-9]+)@@g") echo "title=$TITLE" >> "$GITHUB_OUTPUT" - name: Notify Success - if: needs.publish.result == 'success' && github.event_name == 'push' + if: needs.publish.result == 'success' && needs.sbom.result == 'success' && github.event_name == 'push' uses: slackapi/slack-github-action@v3.0.3 with: webhook-type: incoming-webhook @@ -144,7 +155,7 @@ jobs: payload: | text: " *${{ github.workflow }}* ✅ `${{ github.repository }}` ${{ steps.release.outputs.title || needs.check.outputs.current_tag }} · " - name: Notify Failure - if: needs.publish.result != 'success' + if: needs.publish.result != 'success' || needs.sbom.result != 'success' uses: slackapi/slack-github-action@v3.0.3 with: webhook-type: incoming-webhook