|
| 1 | +name: Update SQLite |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: write |
| 5 | + pull-requests: write |
| 6 | + |
| 7 | +on: |
| 8 | + schedule: |
| 9 | + # Run daily at 9:00 AM PST |
| 10 | + - cron: '0 17 * * *' |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +jobs: |
| 14 | + update-sqlite: |
| 15 | + name: Check for SQLite updates |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Check latest SQLite version |
| 22 | + id: check |
| 23 | + run: | |
| 24 | + apt -y update && apt-get -y install curl |
| 25 | +
|
| 26 | + # Fetch the chronology page and extract the latest version |
| 27 | + page=$(curl -sL -A "Mozilla/5.0" https://sqlite.org/chronology.html) |
| 28 | +
|
| 29 | + # Extract the first (latest) version from the table |
| 30 | + # The page has rows like: <td><a href="releaselog/3_51_3.html">3.51.3</a></td> |
| 31 | + latest_version=$(echo "$page" | grep -oP '(?<=releaselog/)[^"]+(?=\.html)' | head -1 | tr '_' '.') |
| 32 | + if [ -z "$latest_version" ]; then |
| 33 | + echo "Failed to extract latest version" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + echo "Latest SQLite version: $latest_version" |
| 37 | +
|
| 38 | + # Extract the year from the date in the same row |
| 39 | + # Dates appear as YYYY-MM-DD in the table |
| 40 | + latest_year=$(echo "$page" | grep -oP '\d{4}-\d{2}-\d{2}' | head -1 | cut -d'-' -f1) |
| 41 | + if [ -z "$latest_year" ]; then |
| 42 | + echo "Failed to extract year" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + echo "Release year: $latest_year" |
| 46 | +
|
| 47 | + # Convert dotted version (e.g. 3.51.3) to SQLite numeric format (e.g. 3510300) |
| 48 | + IFS='.' read -r major minor patch <<< "$latest_version" |
| 49 | + numeric_version=$(printf "%d%02d%02d00" "$major" "$minor" "$patch") |
| 50 | + echo "Numeric version: $numeric_version" |
| 51 | +
|
| 52 | + # Read current version from update.sh |
| 53 | + current_version=$(grep '^version=' update.sh | head -1 | cut -d'=' -f2) |
| 54 | + echo "Current version: $current_version" |
| 55 | +
|
| 56 | + if [ "$numeric_version" = "$current_version" ]; then |
| 57 | + echo "Already up to date" |
| 58 | + echo "updated=false" >> "$GITHUB_OUTPUT" |
| 59 | + else |
| 60 | + echo "New version available" |
| 61 | + echo "updated=true" >> "$GITHUB_OUTPUT" |
| 62 | + echo "version=$numeric_version" >> "$GITHUB_OUTPUT" |
| 63 | + echo "year=$latest_year" >> "$GITHUB_OUTPUT" |
| 64 | + echo "display_version=$latest_version" >> "$GITHUB_OUTPUT" |
| 65 | + echo "display_version_underscore=$(echo "$latest_version" | tr '.' '_')" >> "$GITHUB_OUTPUT" |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Update update.sh |
| 69 | + if: steps.check.outputs.updated == 'true' |
| 70 | + run: | |
| 71 | + sed -i "s/^year=.*/year=${{ steps.check.outputs.year }}/" update.sh |
| 72 | + sed -i "s/^version=.*/version=${{ steps.check.outputs.version }}/" update.sh |
| 73 | + echo "Updated update.sh:" |
| 74 | + head -5 update.sh |
| 75 | +
|
| 76 | + - name: Run update.sh |
| 77 | + if: steps.check.outputs.updated == 'true' |
| 78 | + run: | |
| 79 | + chmod +x update.sh |
| 80 | + bash update.sh |
| 81 | +
|
| 82 | + - name: Commit, push branch, and create PR |
| 83 | + if: steps.check.outputs.updated == 'true' |
| 84 | + env: |
| 85 | + GH_TOKEN: ${{ github.token }} |
| 86 | + run: | |
| 87 | + git config --global --add safe.directory "$(realpath .)" |
| 88 | + git config --local user.name 'swift-ci' |
| 89 | + git config --local user.email 'swift-ci@users.noreply.github.com' |
| 90 | +
|
| 91 | + PR_BRANCH="automated/sqlite-${{ steps.check.outputs.version }}" |
| 92 | + git checkout -b "$PR_BRANCH" |
| 93 | + git add -A |
| 94 | + git commit -m "Update to sqlite ${{ steps.check.outputs.display_version }}" |
| 95 | + git push --set-upstream origin "$PR_BRANCH" |
| 96 | +
|
| 97 | + gh pr create \ |
| 98 | + --base main \ |
| 99 | + --head "$PR_BRANCH" \ |
| 100 | + --title "Update to sqlite ${{ steps.check.outputs.display_version }}" \ |
| 101 | + --body "Automated update to [SQLite ${{ steps.check.outputs.display_version }}](https://sqlite.org/releaselog/${{ steps.check.outputs.display_version_underscore }}.html). |
| 102 | +
|
| 103 | + See the [SQLite changelog](https://sqlite.org/changes.html) for details." \ |
| 104 | + --draft |
0 commit comments