|
| 1 | +name: amalgamation |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "version-*" |
| 7 | + - "3.*" |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + sqlite_tag: |
| 11 | + description: "Upstream sqlite/sqlite tag to build (e.g. version-3.47.2). Defaults to the contents of SQLITE_TAG." |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + name: Build and release SQLite amalgamation |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Check out this repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Resolve SQLite tag |
| 27 | + id: resolve |
| 28 | + env: |
| 29 | + INPUT_TAG: ${{ inputs.sqlite_tag }} |
| 30 | + run: | |
| 31 | + set -euo pipefail |
| 32 | + TAG="${INPUT_TAG:-}" |
| 33 | + if [ -z "$TAG" ]; then |
| 34 | + if [ ! -f SQLITE_TAG ]; then |
| 35 | + echo "::error::SQLITE_TAG file not found in repository root" |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + TAG="$(tr -d " \t\r\n" < SQLITE_TAG)" |
| 39 | + fi |
| 40 | + if [ -z "$TAG" ]; then |
| 41 | + echo "::error::No SQLite tag given (SQLITE_TAG file is empty)" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + # Accept both "version-3.53.3" and bare "3.53.3" |
| 45 | + case "$TAG" in |
| 46 | + version-*) ;; |
| 47 | + *) TAG="version-$TAG" ;; |
| 48 | + esac |
| 49 | +
|
| 50 | + if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then |
| 51 | + RELEASE_TAG="$GITHUB_REF_NAME" |
| 52 | + # Guard against tagging a release whose SQLITE_TAG file was not updated |
| 53 | + PUSHED="${RELEASE_TAG#version-}" |
| 54 | + WANT="${TAG#version-}" |
| 55 | + case "$PUSHED" in |
| 56 | + "$WANT"*) ;; |
| 57 | + *) |
| 58 | + echo "::error::Pushed tag '$RELEASE_TAG' does not match SQLITE_TAG file contents '$TAG'. Update SQLITE_TAG in the tagged commit, or push a matching tag." |
| 59 | + exit 1 |
| 60 | + ;; |
| 61 | + esac |
| 62 | + else |
| 63 | + RELEASE_TAG="$TAG" |
| 64 | + fi |
| 65 | +
|
| 66 | + echo "Building upstream tag: $TAG (release tag: $RELEASE_TAG)" |
| 67 | + { |
| 68 | + echo "sqlite_tag=$TAG" |
| 69 | + echo "release_tag=$RELEASE_TAG" |
| 70 | + } >> "$GITHUB_OUTPUT" |
| 71 | +
|
| 72 | + - name: Install build dependencies |
| 73 | + run: | |
| 74 | + sudo apt-get update |
| 75 | + sudo apt-get install -y --no-install-recommends tcl tcl-dev zip |
| 76 | +
|
| 77 | + - name: Fetch SQLite source at tag |
| 78 | + run: | |
| 79 | + git clone --depth 1 --branch "${{ steps.resolve.outputs.sqlite_tag }}" \ |
| 80 | + -c advice.detachedHead=false \ |
| 81 | + https://github.com/sqlite/sqlite.git sqlite-src |
| 82 | +
|
| 83 | + - name: Build amalgamation |
| 84 | + working-directory: sqlite-src |
| 85 | + run: | |
| 86 | + set -euo pipefail |
| 87 | + ./configure |
| 88 | + make sqlite3.c |
| 89 | + # Old tags (pre-3.24) ship shell.c as a plain source file instead of a make target |
| 90 | + make shell.c || cp src/shell.c shell.c |
| 91 | +
|
| 92 | + - name: Package |
| 93 | + id: package |
| 94 | + run: | |
| 95 | + set -euo pipefail |
| 96 | + VERSION="$(tr -d " \t\r\n" < sqlite-src/VERSION)" |
| 97 | + IFS=. read -r MAJOR MINOR PATCH BRANCH <<< "$VERSION" |
| 98 | + # sqlite.org download naming: 3.X.Y -> 3XXYY00, 3.X.Y.Z -> 3XXYYZZ (e.g. 3.53.3 -> 3530300) |
| 99 | + NUM="$(printf '%d%02d%02d%02d' "$MAJOR" "$MINOR" "${PATCH:-0}" "${BRANCH:-0}")" |
| 100 | + DIR="sqlite-amalgamation-$NUM" |
| 101 | +
|
| 102 | + mkdir "$DIR" |
| 103 | + cp sqlite-src/sqlite3.c sqlite-src/sqlite3.h sqlite-src/shell.c "$DIR"/ |
| 104 | + cp sqlite-src/src/sqlite3ext.h "$DIR"/ |
| 105 | + zip -9 -r "$DIR.zip" "$DIR" |
| 106 | +
|
| 107 | + (cd "$DIR" && sha256sum sqlite3.c sqlite3.h shell.c sqlite3ext.h) > sha256sums.txt |
| 108 | + sha256sum "$DIR.zip" >> sha256sums.txt |
| 109 | + cat sha256sums.txt |
| 110 | +
|
| 111 | + SOURCE_ID="$(sed -n 's/^#define SQLITE_SOURCE_ID[[:space:]]*"\(.*\)".*/\1/p' "$DIR/sqlite3.h")" |
| 112 | + { |
| 113 | + echo "version=$VERSION" |
| 114 | + echo "dir=$DIR" |
| 115 | + echo "zip=$DIR.zip" |
| 116 | + echo "source_id=$SOURCE_ID" |
| 117 | + } >> "$GITHUB_OUTPUT" |
| 118 | +
|
| 119 | + - name: Create GitHub release |
| 120 | + env: |
| 121 | + GH_TOKEN: ${{ github.token }} |
| 122 | + RELEASE_TAG: ${{ steps.resolve.outputs.release_tag }} |
| 123 | + SQLITE_TAG: ${{ steps.resolve.outputs.sqlite_tag }} |
| 124 | + VERSION: ${{ steps.package.outputs.version }} |
| 125 | + DIR: ${{ steps.package.outputs.dir }} |
| 126 | + ZIP: ${{ steps.package.outputs.zip }} |
| 127 | + SOURCE_ID: ${{ steps.package.outputs.source_id }} |
| 128 | + run: | |
| 129 | + set -euo pipefail |
| 130 | + ASSETS=("$ZIP" "$DIR/sqlite3.c" "$DIR/sqlite3.h" "$DIR/shell.c" "$DIR/sqlite3ext.h" sha256sums.txt) |
| 131 | +
|
| 132 | + { |
| 133 | + echo "SQLite **$VERSION** amalgamation, built from [sqlite/sqlite tag \`$SQLITE_TAG\`](https://github.com/sqlite/sqlite/releases/tag/$SQLITE_TAG) with \`./configure && make sqlite3.c shell.c\` on ubuntu-latest." |
| 134 | + echo |
| 135 | + echo '```' |
| 136 | + echo "SQLITE_SOURCE_ID: $SOURCE_ID" |
| 137 | + echo '```' |
| 138 | + echo |
| 139 | + echo "\`$ZIP\` matches the sqlite.org download layout (sqlite3.c, sqlite3.h, shell.c, sqlite3ext.h); the same four files are also attached individually, plus \`sha256sums.txt\`." |
| 140 | + } > notes.md |
| 141 | +
|
| 142 | + if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then |
| 143 | + echo "Release $RELEASE_TAG already exists; replacing assets" |
| 144 | + gh release upload "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --clobber "${ASSETS[@]}" |
| 145 | + else |
| 146 | + gh release create "$RELEASE_TAG" \ |
| 147 | + --repo "$GITHUB_REPOSITORY" \ |
| 148 | + --target "$GITHUB_SHA" \ |
| 149 | + --title "SQLite $VERSION amalgamation" \ |
| 150 | + --notes-file notes.md \ |
| 151 | + "${ASSETS[@]}" |
| 152 | + fi |
0 commit comments