diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-04-20 19:34:56 +0200 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-04-20 19:34:56 +0200 |
| commit | c86b4655f72c86362c064dd50bb701782b39e6eb (patch) | |
| tree | 8b4cbd399e984f599044147ee8d74c40ae6a153a /.github/workflows/update-stops-data.yml | |
| parent | 340865ad234f974ec4c0afcbfb6ff06f50a11b2f (diff) | |
Update stop overrides
Diffstat (limited to '.github/workflows/update-stops-data.yml')
| -rw-r--r-- | .github/workflows/update-stops-data.yml | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/.github/workflows/update-stops-data.yml b/.github/workflows/update-stops-data.yml new file mode 100644 index 0000000..1b72cdc --- /dev/null +++ b/.github/workflows/update-stops-data.yml @@ -0,0 +1,65 @@ +name: Update Stops Data + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + +jobs: + update-stops-data: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Run download script + run: python data/download-stops.py + + - name: Commit changes if any + id: commit + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + git add public/stops.json + if git diff --staged --exit-code; then + echo "No changes to commit" + echo "changes_made=false" >> $GITHUB_OUTPUT + else + # Create a new branch with timestamp + BRANCH_NAME="update-stops-data-$(date +%Y-%m-%d-%H%M%S)" + git checkout -b $BRANCH_NAME + git commit -m "Update stops data" + git push origin $BRANCH_NAME + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT + echo "changes_made=true" >> $GITHUB_OUTPUT + fi + + - name: Create Pull Request + if: steps.commit.outputs.changes_made == 'true' + env: + GH_TOKEN: ${{ github.token }} + BRANCH_NAME: ${{ steps.commit.outputs.branch_name }} + run: | + # Close any existing PRs created by this action + existing_prs=$(gh pr list --json number,title,headRefName --search "Update stops data in:title head:update-stops-data- author:app/github-actions is:open") + + if [[ $(echo "$existing_prs" | jq length) -gt 0 ]]; then + echo "Found existing PRs to close" + echo "$existing_prs" | jq -c '.[]' | while read pr; do + pr_number=$(echo "$pr" | jq -r '.number') + echo "Closing PR #$pr_number" + gh pr close $pr_number --comment "Superseded by a new PR with updated data" + done + fi + + # Create new PR + gh pr create \ + --title "Update stops data" \ + --body "Automatically generated PR with updated stops data from scheduled fetch." \ + --base main \ + --head "$BRANCH_NAME"
\ No newline at end of file |
