Update Bezel JSON #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Bezel JSON | |
| on: | |
| schedule: | |
| - cron: "0 6 * * 1" # every Monday 06:00 UTC | |
| workflow_dispatch: {} | |
| jobs: | |
| sync-bezel-json: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| changes_committed: ${{ steps.commit.outputs.committed }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Fetch latest bezel.min.json | |
| run: | | |
| curl -L -o assets/bezel.min.json \ | |
| https://raw.githubusercontent.com/markbattistella/BezelKit/main/Sources/BezelKit/Resources/bezel.min.json | |
| - name: Update version, changelog and commit changes | |
| id: commit | |
| env: | |
| REPO_PUSH_TOKEN: ${{ secrets.REPO_PUSH_TOKEN }} | |
| run: | | |
| if git diff --quiet; then | |
| echo "No changes" | |
| echo "committed=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "committed=true" >> $GITHUB_OUTPUT | |
| git config user.name "github-actions" | |
| git config user.email "ketanchoyal@users.noreply.github.com" | |
| # If a repository personal access token is provided (recommended when | |
| # branch protection prevents the default GITHUB_TOKEN from pushing), | |
| # configure the remote to use it. Otherwise rely on the default token. | |
| if [ -n "$REPO_PUSH_TOKEN" ]; then | |
| remote_url=$(git remote get-url origin) | |
| # craft an https remote with the token; keep the host/path | |
| auth_remote=$(echo "$remote_url" | sed -E "s#https://(.*)#https://$REPO_PUSH_TOKEN@\1#") | |
| git remote set-url origin "$auth_remote" | |
| fi | |
| # Bump patch version in pubspec.yaml (semver) | |
| if [ -f pubspec.yaml ]; then | |
| version_line=$(grep '^version:' pubspec.yaml || true) | |
| if [ -n "$version_line" ]; then | |
| # extract the version number | |
| current_version=$(echo "$version_line" | sed -E 's/version:[[:space:]]*([0-9]+\.[0-9]+\.[0-9]+).*/\1/') | |
| IFS='.' read -r major minor patch <<< "$current_version" | |
| patch=$((patch + 1)) | |
| new_version="$major.$minor.$patch" | |
| # replace the version line (preserve any suffix like +build if present) | |
| sed -E "s/^(version:[[:space:]]*)([0-9]+\.[0-9]+\.[0-9]+)(.*)/\1${new_version}\3/" -i.bak pubspec.yaml || true | |
| rm -f pubspec.yaml.bak | |
| fi | |
| fi | |
| # Prepend changelog entry to CHANGELOG.md | |
| if [ -f CHANGELOG.md ]; then | |
| date_str=$(date -u +"%Y-%m-%d") | |
| # Use the user's requested text "Device dataset Updated" (preserve spelling) | |
| header="## ${new_version} - ${date_str}\n\nDevice dataset Updated\n\n" | |
| # Create a temp file and write header + existing content | |
| tmpfile=$(mktemp) | |
| printf "%b" "$header" > "$tmpfile" | |
| cat CHANGELOG.md >> "$tmpfile" | |
| mv "$tmpfile" CHANGELOG.md | |
| fi | |
| git add assets/bezel.min.json pubspec.yaml CHANGELOG.md | |
| git commit -m "automated: chore(ios): update bezel.min.json, bump version to ${new_version} and update CHANGELOG" | |
| git push | |
| # Call the publish workflow only when changes were committed | |
| call-publish: | |
| needs: sync-bezel-json | |
| if: needs.sync-bezel-json.outputs.changes_committed == 'true' | |
| uses: ./.github/workflows/publish_to_pub.yml | |
| secrets: | |
| CREDENTIAL_JSON: ${{ secrets.CREDENTIAL_JSON }} |