|
| 1 | +name: Build SQLite Wasm |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + sqlite_ref: |
| 7 | + description: 'SQLite reference (tag, branch, or commit, or "latest")' |
| 8 | + required: true |
| 9 | + default: 'master' |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v6 |
| 17 | + with: |
| 18 | + persist-credentials: false |
| 19 | + |
| 20 | + - name: Resolve SQLite reference |
| 21 | + id: resolve-ref |
| 22 | + run: | |
| 23 | + SQLITE_REF="${{ github.event.inputs.sqlite_ref }}" |
| 24 | + if [ "$SQLITE_REF" = "latest" ]; then |
| 25 | + echo "Fetching latest tag..." |
| 26 | + LATEST_TAG=$(git ls-remote --tags --sort="v:refname" https://github.com/sqlite/sqlite.git "refs/tags/version-*" | tail -n 1 | cut -f 2 | sed 's/refs\/tags\///') |
| 27 | + echo "Latest tag found: $LATEST_TAG" |
| 28 | + SQLITE_REF="$LATEST_TAG" |
| 29 | + fi |
| 30 | +
|
| 31 | + # Get the full commit SHA |
| 32 | + SQLITE_SHA=$(git ls-remote https://github.com/sqlite/sqlite.git "$SQLITE_REF" | head -n 1 | cut -f 1) |
| 33 | + if [ -z "$SQLITE_SHA" ]; then |
| 34 | + # If not found, maybe it's a tag that needs refs/tags/ prefix or it's already a SHA |
| 35 | + SQLITE_SHA=$(git ls-remote https://github.com/sqlite/sqlite.git "refs/tags/$SQLITE_REF" | head -n 1 | cut -f 1) |
| 36 | + fi |
| 37 | +
|
| 38 | + if [ -z "$SQLITE_SHA" ]; then |
| 39 | + # Fallback: assume it's a SHA if ls-remote didn't find it as a ref |
| 40 | + SQLITE_SHA="$SQLITE_REF" |
| 41 | + fi |
| 42 | +
|
| 43 | + echo "sqlite_ref=$SQLITE_REF" >> $GITHUB_OUTPUT |
| 44 | + echo "sqlite_sha=$SQLITE_SHA" >> $GITHUB_OUTPUT |
| 45 | + echo "branch_name=update-sqlite-wasm-${SQLITE_SHA}" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + - name: Check if branch exists |
| 48 | + id: check-branch |
| 49 | + run: | |
| 50 | + BRANCH_NAME="${{ steps.resolve-ref.outputs.branch_name }}" |
| 51 | + if git ls-remote --exit-code --heads origin "$BRANCH_NAME"; then |
| 52 | + echo "Branch $BRANCH_NAME already exists. Skipping build." |
| 53 | + echo "skip=true" >> $GITHUB_OUTPUT |
| 54 | + else |
| 55 | + echo "skip=false" >> $GITHUB_OUTPUT |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Set up Buildx Docker CLI plugin |
| 59 | + if: steps.check-branch.outputs.skip != 'true' |
| 60 | + uses: docker/setup-buildx-action@v3 |
| 61 | + |
| 62 | + - name: Build Docker image |
| 63 | + if: steps.check-branch.outputs.skip != 'true' |
| 64 | + uses: docker/build-push-action@v6 |
| 65 | + with: |
| 66 | + context: . |
| 67 | + load: true |
| 68 | + tags: sqlite-wasm-builder:env |
| 69 | + cache-from: type=gha |
| 70 | + cache-to: type=gha,mode=max |
| 71 | + |
| 72 | + - name: Run build |
| 73 | + if: steps.check-branch.outputs.skip != 'true' |
| 74 | + run: | |
| 75 | + mkdir -p out src/bin |
| 76 | + docker run --rm \ |
| 77 | + -e SQLITE_REF="${{ steps.resolve-ref.outputs.sqlite_ref }}" \ |
| 78 | + -e HOST_UID="$(id -u)" \ |
| 79 | + -e HOST_GID="$(id -g)" \ |
| 80 | + -v "$(pwd)/out":/out \ |
| 81 | + -v "$(pwd)/src/bin":/src/bin \ |
| 82 | + sqlite-wasm-builder:env build |
| 83 | + # Fallback fix for permissions if chown inside docker failed or was incomplete |
| 84 | + sudo chown -R $(id -u):$(id -g) out src/bin |
| 85 | +
|
| 86 | + - name: Check for changes |
| 87 | + if: steps.check-branch.outputs.skip != 'true' |
| 88 | + id: git-check |
| 89 | + run: | |
| 90 | + # Add files that might be newly created or modified |
| 91 | + git add src/bin |
| 92 | + git status --porcelain |
| 93 | + if [ -n "$(git status --porcelain)" ]; then |
| 94 | + echo "changes=true" >> $GITHUB_OUTPUT |
| 95 | + else |
| 96 | + echo "changes=false" >> $GITHUB_OUTPUT |
| 97 | + fi |
| 98 | +
|
| 99 | + - name: Create Pull Request |
| 100 | + if: |
| 101 | + steps.check-branch.outputs.skip != 'true' && |
| 102 | + steps.git-check.outputs.changes == 'true' |
| 103 | + uses: peter-evans/create-pull-request@v6 |
| 104 | + with: |
| 105 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + commit-message: |
| 107 | + 'chore: update SQLite Wasm binaries from ${{ |
| 108 | + steps.resolve-ref.outputs.sqlite_ref }} (${{ |
| 109 | + steps.resolve-ref.outputs.sqlite_sha }})' |
| 110 | + title: |
| 111 | + 'chore: update SQLite Wasm binaries from ${{ |
| 112 | + steps.resolve-ref.outputs.sqlite_ref }}' |
| 113 | + body: | |
| 114 | + This PR updates the SQLite Wasm binaries in `src/bin` by building them from SQLite reference `${{ steps.resolve-ref.outputs.sqlite_ref }}` (commit `${{ steps.resolve-ref.outputs.sqlite_sha }}`). |
| 115 | +
|
| 116 | + Triggered by manual workflow dispatch. |
| 117 | + branch: ${{ steps.resolve-ref.outputs.branch_name }} |
| 118 | + base: main |
| 119 | + delete-branch: true |
0 commit comments