diff --git a/.github/workflows/crowdin.yml b/.github/workflows/crowdin.yml index 737219f60..336da9fbc 100644 --- a/.github/workflows/crowdin.yml +++ b/.github/workflows/crowdin.yml @@ -3,6 +3,7 @@ name: Crowdin Action on: push: branches: [ master ] + workflow_dispatch: # Allow manual triggering jobs: synchronize-with-crowdin: diff --git a/.github/workflows/update-hardware-list.yml b/.github/workflows/update-hardware-list.yml new file mode 100644 index 000000000..067d13f4e --- /dev/null +++ b/.github/workflows/update-hardware-list.yml @@ -0,0 +1,75 @@ +name: Update Hardware List + +on: + schedule: + - cron: '0 * * * *' # Run every hour + workflow_dispatch: # Allow manual triggering + +jobs: + update-hardware-list: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Fetch latest device hardware data + id: fetch-data + run: | + # Define variables for file paths + device_hardware_json="public/data/app/src/main/assets/device_hardware.json" + new_device_hardware_json="/tmp/new_device_hardware.json" + + # Fetch data from API + curl -s --fail https://api.meshtastic.org/resource/deviceHardware > "$new_device_hardware_json" + + # Ensure the output is valid JSON + if ! jq empty "$new_device_hardware_json" 2>/dev/null; then + echo "::error::API returned invalid JSON data" + exit 1 + fi + + # Check if "$device_hardware_json" exists + if [ -f "$device_hardware_json" ]; then + # Format both files for consistent comparison + jq --sort-keys . "$new_device_hardware_json" > /tmp/new-formatted.json + jq --sort-keys . "$device_hardware_json" > /tmp/existing-formatted.json + + # Compare files + if cmp -s /tmp/new-formatted.json /tmp/existing-formatted.json; then + echo "No changes detected in hardware list" + echo "has_changes=false" >> $GITHUB_OUTPUT + else + echo "Changes detected in hardware list" + echo "has_changes=true" >> $GITHUB_OUTPUT + fi + else + echo "device_hardware.json doesn't exist yet" + echo "has_changes=true" >> $GITHUB_OUTPUT + fi + + # Copy new data to destination + cp "$new_device_hardware_json" "$device_hardware_json" + + - name: Create Pull Request + if: steps.fetch-data.outputs.has_changes == 'true' + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "chore: update device hardware list from Meshtastic API" + title: "chore: update device hardware list from Meshtastic API" + body: | + This PR updates the device hardware list with the latest data from the Meshtastic API. + + This PR was automatically generated by the update-hardware-list workflow. + branch: update-hardware-list + base: main + delete-branch: true \ No newline at end of file