|
| 1 | +name: Update Postman Collections |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 9 * * 1" # Monday 9am UTC |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + update: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - uses: actions/setup-go@v5 |
| 18 | + with: |
| 19 | + go-version: "1.23" |
| 20 | + |
| 21 | + - uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: "3.12" |
| 24 | + |
| 25 | + - name: Save old spec |
| 26 | + run: | |
| 27 | + cd codegen && python3 extract_api_spec.py |
| 28 | + cp codegen/api_spec.json /tmp/old_spec.json |
| 29 | +
|
| 30 | + - name: Download collections |
| 31 | + run: cd codegen && python3 download_collections.py |
| 32 | + |
| 33 | + - name: Run codegen |
| 34 | + run: | |
| 35 | + cd codegen && python3 extract_api_spec.py |
| 36 | + cd codegen && python3 generate_cli.py |
| 37 | +
|
| 38 | + - name: Build and vet |
| 39 | + run: | |
| 40 | + go build -o webex . |
| 41 | + go vet ./... |
| 42 | +
|
| 43 | + - name: Generate changelog |
| 44 | + id: changelog |
| 45 | + run: | |
| 46 | + DIFF=$(python3 codegen/diff_spec.py /tmp/old_spec.json codegen/api_spec.json) |
| 47 | + # Write to file to preserve formatting across steps |
| 48 | + echo "$DIFF" > /tmp/spec_diff.md |
| 49 | +
|
| 50 | + - name: Check for changes |
| 51 | + id: changes |
| 52 | + run: | |
| 53 | + if git diff --quiet; then |
| 54 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 55 | + else |
| 56 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Create PR |
| 60 | + if: steps.changes.outputs.changed == 'true' |
| 61 | + env: |
| 62 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + run: | |
| 64 | + BRANCH="auto/update-postman-collections" |
| 65 | + git config user.name "github-actions[bot]" |
| 66 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 67 | + git checkout -B "$BRANCH" |
| 68 | + git add -A |
| 69 | + git commit -m "Update Postman collections and regenerate CLI commands" |
| 70 | + git push -f origin "$BRANCH" |
| 71 | + if ! gh pr list --head "$BRANCH" --state open | grep -q .; then |
| 72 | + CHANGELOG=$(cat /tmp/spec_diff.md) |
| 73 | + gh pr create \ |
| 74 | + --title "Update Postman collections" \ |
| 75 | + --body "$(cat <<EOF |
| 76 | + ## Summary |
| 77 | +
|
| 78 | + Automated update of Postman collections and regenerated CLI commands. |
| 79 | +
|
| 80 | + ## API Changes |
| 81 | +
|
| 82 | + ${CHANGELOG} |
| 83 | + EOF |
| 84 | + )" \ |
| 85 | + --head "$BRANCH" \ |
| 86 | + --base main |
| 87 | + fi |
0 commit comments