From 9981f6109c84c2a96bb8207a4a88f61acf241ebe Mon Sep 17 00:00:00 2001 From: Daniele Briggi <=> Date: Mon, 1 Sep 2025 18:57:37 +0200 Subject: [PATCH 1/2] fix(workflow): trigger when main workflow completes - release or publish trigger doesn't work when the relase is done by another workflow --- .github/workflows/main.yml | 54 +------------------------- .github/workflows/python-package.yml | 18 ++++++--- .github/workflows/release.yml | 58 ++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7bfa165..7f430ee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Build, Test and Release SQLite AI +name: Build and Test on: push: workflow_dispatch: @@ -358,55 +358,3 @@ jobs: name: ai-${{ matrix.name }}${{ matrix.arch && format('-{0}', matrix.arch) || '' }} path: dist/ai.* if-no-files-found: error - - release: - runs-on: ubuntu-22.04 - name: release - needs: build - if: github.ref == 'refs/heads/main' - - steps: - - - uses: actions/checkout@v4.2.2 - - - uses: actions/download-artifact@v4.2.1 - with: - path: artifacts - - - name: release tag version from sqlite-ai.h - id: tag - run: | - VERSION=$(make version) - if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - LATEST=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.name') - if [[ "$VERSION" != "$LATEST" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then - echo "version=$VERSION" >> $GITHUB_OUTPUT - else - echo "::warning file=src/sqlite-ai.h::To release a new version, please update the SQLITE_AI_VERSION in src/sqlite-ai.h to be different than the latest $LATEST" - fi - exit 0 - fi - echo "❌ SQLITE_AI_VERSION not found in sqlite-ai.h" - exit 1 - - - name: zip artifacts - run: | - for folder in "artifacts"/*; do - if [ -d "$folder" ]; then - name=$(basename "$folder") - if [[ "$name" != "ai-apple-xcframework" ]]; then - tar -czf "${name}-${{ steps.tag.outputs.version }}.tar.gz" -C "$folder" . - fi - (cd "$folder" && zip -rq "../../${name}-${{ steps.tag.outputs.version }}.zip" .) - fi - done - - - uses: softprops/action-gh-release@v2.2.1 - if: steps.tag.outputs.version != '' - with: - generate_release_notes: true - tag_name: ${{ steps.tag.outputs.version }} - files: | - ai-*-${{ steps.tag.outputs.version }}.zip - ai-*-${{ steps.tag.outputs.version }}.tar.gz - make_latest: true diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 58e8f52..0fdc9cf 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -7,14 +7,19 @@ on: description: "Version to use for the Python package (e.g. 0.5.9)" required: true type: string - release: - types: [released] + workflow_run: + workflows: ["Release"] + types: + - completed jobs: build-and-publish: + if: | + github.event_name == 'workflow_dispatch' || + (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main') runs-on: ${{ matrix.os }} permissions: - id-token: write # mandatory for Pypi trusted publishing + id-token: write # mandatory for Pypi trusted publishing strategy: matrix: include: @@ -42,7 +47,7 @@ jobs: platform: macos python-version: "3.10" arch: arm64 - plat_name: macosx_11_0_arm64 + plat_name: macosx_11_0_arm64 defaults: run: shell: bash @@ -65,8 +70,9 @@ jobs: - name: Get version id: get_version run: | - if [[ "${{ github.event_name }}" == "release" ]]; then - VERSION="${{ github.event.release.tag_name }}" + if [[ "${{ github.event_name }}" == "workflow_run" ]]; then + # Fetch latest published release tag from GitHub API + VERSION=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r '.tag_name') else VERSION="${{ github.event.inputs.version }}" fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..49a6767 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +name: Release + +on: + workflow_run: + workflows: ["Build and Test"] + types: + - completed + +jobs: + release: + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' + runs-on: ubuntu-22.04 + name: release + steps: + - uses: actions/checkout@v4.2.2 + + - uses: actions/download-artifact@v4.2.1 + with: + path: artifacts + run-id: ${{ github.event.workflow_run.id }} + + - name: release tag version from sqlite-ai.h + id: tag + run: | + VERSION=$(make version) + if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + LATEST=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.name') + if [[ "$VERSION" != "$LATEST" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then + echo "version=$VERSION" >> $GITHUB_OUTPUT + else + echo "::warning file=src/sqlite-ai.h::To release a new version, please update the SQLITE_AI_VERSION in src/sqlite-ai.h to be different than the latest $LATEST" + fi + exit 0 + fi + echo "❌ SQLITE_AI_VERSION not found in sqlite-ai.h" + exit 1 + + - name: zip artifacts + run: | + for folder in "artifacts"/*; do + if [ -d "$folder" ]; then + name=$(basename "$folder") + if [[ "$name" != "ai-apple-xcframework" ]]; then + tar -czf "${name}-${{ steps.tag.outputs.version }}.tar.gz" -C "$folder" . + fi + (cd "$folder" && zip -rq "../../${name}-${{ steps.tag.outputs.version }}.zip" .) + fi + done + + - uses: softprops/action-gh-release@v2.2.1 + if: steps.tag.outputs.version != '' + with: + generate_release_notes: true + tag_name: ${{ steps.tag.outputs.version }} + files: | + ai-*-${{ steps.tag.outputs.version }}.zip + ai-*-${{ steps.tag.outputs.version }}.tar.gz + make_latest: true From e2150c780a27d4280f723cc5e071b28a88617e08 Mon Sep 17 00:00:00 2001 From: Daniele Briggi <=> Date: Tue, 2 Sep 2025 14:55:59 +0200 Subject: [PATCH 2/2] fix(workflow): trigger after the build and release workflow --- .github/workflows/main.yml | 54 +++++++++++++++++++++++++- .github/workflows/python-package.yml | 2 +- .github/workflows/release.yml | 58 ---------------------------- 3 files changed, 54 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7f430ee..3e1f70a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Build and Test +name: Build, Test and Release on: push: workflow_dispatch: @@ -358,3 +358,55 @@ jobs: name: ai-${{ matrix.name }}${{ matrix.arch && format('-{0}', matrix.arch) || '' }} path: dist/ai.* if-no-files-found: error + + release: + runs-on: ubuntu-22.04 + name: release + needs: build + if: github.ref == 'refs/heads/main' + + steps: + + - uses: actions/checkout@v4.2.2 + + - uses: actions/download-artifact@v4.2.1 + with: + path: artifacts + + - name: release tag version from sqlite-ai.h + id: tag + run: | + VERSION=$(make version) + if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + LATEST=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.name') + if [[ "$VERSION" != "$LATEST" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then + echo "version=$VERSION" >> $GITHUB_OUTPUT + else + echo "::warning file=src/sqlite-ai.h::To release a new version, please update the SQLITE_AI_VERSION in src/sqlite-ai.h to be different than the latest $LATEST" + fi + exit 0 + fi + echo "❌ SQLITE_AI_VERSION not found in sqlite-ai.h" + exit 1 + + - name: zip artifacts + run: | + for folder in "artifacts"/*; do + if [ -d "$folder" ]; then + name=$(basename "$folder") + if [[ "$name" != "ai-apple-xcframework" ]]; then + tar -czf "${name}-${{ steps.tag.outputs.version }}.tar.gz" -C "$folder" . + fi + (cd "$folder" && zip -rq "../../${name}-${{ steps.tag.outputs.version }}.zip" .) + fi + done + + - uses: softprops/action-gh-release@v2.2.1 + if: steps.tag.outputs.version != '' + with: + generate_release_notes: true + tag_name: ${{ steps.tag.outputs.version }} + files: | + ai-*-${{ steps.tag.outputs.version }}.zip + ai-*-${{ steps.tag.outputs.version }}.tar.gz + make_latest: true diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 0fdc9cf..e78eb1f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -8,7 +8,7 @@ on: required: true type: string workflow_run: - workflows: ["Release"] + workflows: ["Build, Test and Release"] types: - completed diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 49a6767..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Release - -on: - workflow_run: - workflows: ["Build and Test"] - types: - - completed - -jobs: - release: - if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' - runs-on: ubuntu-22.04 - name: release - steps: - - uses: actions/checkout@v4.2.2 - - - uses: actions/download-artifact@v4.2.1 - with: - path: artifacts - run-id: ${{ github.event.workflow_run.id }} - - - name: release tag version from sqlite-ai.h - id: tag - run: | - VERSION=$(make version) - if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - LATEST=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r '.name') - if [[ "$VERSION" != "$LATEST" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then - echo "version=$VERSION" >> $GITHUB_OUTPUT - else - echo "::warning file=src/sqlite-ai.h::To release a new version, please update the SQLITE_AI_VERSION in src/sqlite-ai.h to be different than the latest $LATEST" - fi - exit 0 - fi - echo "❌ SQLITE_AI_VERSION not found in sqlite-ai.h" - exit 1 - - - name: zip artifacts - run: | - for folder in "artifacts"/*; do - if [ -d "$folder" ]; then - name=$(basename "$folder") - if [[ "$name" != "ai-apple-xcframework" ]]; then - tar -czf "${name}-${{ steps.tag.outputs.version }}.tar.gz" -C "$folder" . - fi - (cd "$folder" && zip -rq "../../${name}-${{ steps.tag.outputs.version }}.zip" .) - fi - done - - - uses: softprops/action-gh-release@v2.2.1 - if: steps.tag.outputs.version != '' - with: - generate_release_notes: true - tag_name: ${{ steps.tag.outputs.version }} - files: | - ai-*-${{ steps.tag.outputs.version }}.zip - ai-*-${{ steps.tag.outputs.version }}.tar.gz - make_latest: true