Skip to content

Update Metadata

Update Metadata #29

name: Update Metadata
on:
schedule:
# At 12:00 AM, on day 1 of each month
- cron: "0 0 1 * *"
workflow_dispatch:
jobs:
update-workflow:
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🛠️ Setup Dart
uses: dart-lang/setup-dart@v1
with:
sdk: "beta"
- name: 📦 Install dependencies
run: dart pub get
- name: 📥 Fetch LibPhoneNumber Metadata
run: curl -s -o resources/data_sources/PhoneNumberMetadata.xml https://raw.githubusercontent.com/google/libphonenumber/master/resources/PhoneNumberMetadata.xml
- name: 🔄 Process Metadata
run: dart resources/data_sources/convert_metadata.dart
- name: 🔍 Detect changes in metadata
id: metadata_changes
run: |
if git diff --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "✅ No metadata changes detected."
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "⚠️ Metadata changes detected, continuing..."
fi
- name: ⚙️ Generate Files
if: steps.metadata_changes.outputs.changed == 'true'
run: |
dart pub get
dart resources/generate_files.dart
dart format lib/src
dart fix --apply
- name: ⬆️ Bump Version
if: steps.metadata_changes.outputs.changed == 'true'
id: bump
run: |
dart pub bump patch
NEW_VERSION=$(grep 'version:' pubspec.yaml | sed 's/version: //')
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "📦 Bumped to version $NEW_VERSION"
- name: 📝 Update CHANGELOG.md
if: steps.metadata_changes.outputs.changed == 'true'
run: |
NEW_VERSION=${{ steps.bump.outputs.new_version }}
TEMP_FILE=$(mktemp)
echo "## $NEW_VERSION" > $TEMP_FILE
echo "- Upgrade metadata" >> $TEMP_FILE
echo "" >> $TEMP_FILE
cat CHANGELOG.md >> $TEMP_FILE
mv $TEMP_FILE CHANGELOG.md
echo "🆕 Added changelog entry for $NEW_VERSION"
- name: 🌿 Create Branch, Commit & Push
if: steps.metadata_changes.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
NEW_VERSION=${{ steps.bump.outputs.new_version }}
BRANCH="update-metadata-$NEW_VERSION"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
git add .
git commit -m "🔄 Update metadata and bump version to $NEW_VERSION"
git push origin "$BRANCH"
echo "🌿 Created and pushed branch $BRANCH"
- name: 🚀 Create Pull Request
if: steps.metadata_changes.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
NEW_VERSION=${{ steps.bump.outputs.new_version }}
BRANCH="update-metadata-$NEW_VERSION"
gh pr create \
--title "🔄 Update metadata and bump version to $NEW_VERSION" \
--body "This PR updates the metadata and bumps the package version to $NEW_VERSION." \
--base main \
--head "$BRANCH"
echo "✅ Pull request created for branch $BRANCH"
- name: 🤝 Merge Pull Request
if: steps.metadata_changes.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
NEW_VERSION=${{ steps.bump.outputs.new_version }}
BRANCH="update-metadata-$NEW_VERSION"
echo "🔄 Attempting to merge PR for branch: $BRANCH"
gh pr merge "$BRANCH" --squash --admin --delete-branch
echo "🎉 Pull request merged successfully!"