|
| 1 | +# (C) 2026 GoodData Corporation |
| 2 | +# This workflow regenerates the API client from the latest OpenAPI schema and updates VCR cassettes. |
| 3 | +# It creates a PR with the updated API client and cassettes. |
| 4 | + |
| 5 | +name: Regenerate API Client |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + branch_name: |
| 11 | + description: 'Branch name for the PR' |
| 12 | + required: false |
| 13 | + default: 'chore/regenerate-api-client' |
| 14 | + pr_title: |
| 15 | + description: 'PR title' |
| 16 | + required: false |
| 17 | + default: 'chore: Regenerate API client' |
| 18 | + |
| 19 | +# Security: Only allow running on protected branches to prevent secret exfiltration |
| 20 | +# via malicious Makefile modifications on feature branches |
| 21 | +env: |
| 22 | + ALLOWED_BRANCHES: 'refs/heads/master refs/heads/main' |
| 23 | + |
| 24 | +permissions: |
| 25 | + contents: write |
| 26 | + pull-requests: write |
| 27 | + |
| 28 | +jobs: |
| 29 | + regenerate-api-client: |
| 30 | + name: Regenerate API Client |
| 31 | + runs-on: ubuntu-latest |
| 32 | + timeout-minutes: 60 |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Verify branch is allowed |
| 36 | + run: | |
| 37 | + echo "Current ref: ${{ github.ref }}" |
| 38 | + if [[ ! " ${{ env.ALLOWED_BRANCHES }} " =~ " ${{ github.ref }} " ]]; then |
| 39 | + echo "::error::This workflow can only be run on protected branches (master/main) to prevent credential hijacking." |
| 40 | + echo "::error::Current branch '${{ github.ref }}' is not in the allowed list." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + echo "Branch verification passed." |
| 44 | +
|
| 45 | + - name: Checkout |
| 46 | + uses: actions/checkout@v4 |
| 47 | + with: |
| 48 | + fetch-depth: 0 |
| 49 | + |
| 50 | + - name: Configure AWS credentials |
| 51 | + uses: aws-actions/configure-aws-credentials@v4 |
| 52 | + with: |
| 53 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 54 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 55 | + aws-region: us-east-1 |
| 56 | + |
| 57 | + - name: Login to Amazon ECR |
| 58 | + id: login-ecr |
| 59 | + uses: aws-actions/amazon-ecr-login@v2 |
| 60 | + |
| 61 | + - name: Create license file |
| 62 | + run: | |
| 63 | + mkdir -p build |
| 64 | + echo "${{ secrets.GOODDATA_LICENSE_KEY }}" > build/license |
| 65 | +
|
| 66 | + - name: Install jq |
| 67 | + run: sudo apt-get update && sudo apt-get install -y jq |
| 68 | + |
| 69 | + - name: Start Docker Compose services |
| 70 | + run: | |
| 71 | + docker compose up -d |
| 72 | + echo "Docker Compose services started" |
| 73 | +
|
| 74 | + - name: Wait for all services to be ready |
| 75 | + run: | |
| 76 | + echo "Waiting for bootstrap services to complete..." |
| 77 | +
|
| 78 | + # Wait for layout-uploader to complete (last bootstrap step) |
| 79 | + echo "Waiting for layout-uploader to complete..." |
| 80 | + timeout 600 bash -c ' |
| 81 | + while true; do |
| 82 | + status=$(docker compose ps layout-uploader --format json 2>/dev/null | jq -r ".State" 2>/dev/null || echo "unknown") |
| 83 | + exit_code=$(docker compose ps layout-uploader --format json 2>/dev/null | jq -r ".ExitCode" 2>/dev/null || echo "-1") |
| 84 | +
|
| 85 | + if [ "$status" = "exited" ] && [ "$exit_code" = "0" ]; then |
| 86 | + echo "layout-uploader completed successfully!" |
| 87 | + break |
| 88 | + elif [ "$status" = "exited" ] && [ "$exit_code" != "0" ]; then |
| 89 | + echo "layout-uploader failed with exit code $exit_code" |
| 90 | + docker compose logs layout-uploader |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | +
|
| 94 | + echo "layout-uploader status: $status, waiting..." |
| 95 | + sleep 10 |
| 96 | + done |
| 97 | + ' |
| 98 | +
|
| 99 | + # Verify api-gw is healthy |
| 100 | + echo "Verifying api-gw is ready..." |
| 101 | + timeout 60 bash -c ' |
| 102 | + while ! curl -sf http://localhost:3000/api/v1/entities/admin/organizations 2>/dev/null; do |
| 103 | + echo "Waiting for api-gw to respond..." |
| 104 | + sleep 5 |
| 105 | + done |
| 106 | + ' |
| 107 | + echo "All services are ready!" |
| 108 | +
|
| 109 | + - name: Set up Python |
| 110 | + uses: astral-sh/setup-uv@v6 |
| 111 | + with: |
| 112 | + python-version: "3.14" |
| 113 | + |
| 114 | + - name: Generate API client |
| 115 | + run: make api-client |
| 116 | + |
| 117 | + - name: Remove existing cassettes |
| 118 | + run: make remove-cassettes |
| 119 | + |
| 120 | + - name: Install development dependencies |
| 121 | + run: make dev |
| 122 | + |
| 123 | + - name: Run tests to regenerate cassettes |
| 124 | + run: make test |
| 125 | + env: |
| 126 | + HOST: "http://localhost:3000" |
| 127 | + TOKEN: "YWRtaW46Ym9vdHN0cmFwOmFkbWluMTIz" |
| 128 | + |
| 129 | + - name: Show Docker Compose logs on failure |
| 130 | + if: failure() |
| 131 | + run: | |
| 132 | + echo "=== Docker Compose Status ===" |
| 133 | + docker compose ps |
| 134 | + echo "" |
| 135 | + echo "=== Docker Compose Logs ===" |
| 136 | + docker compose logs --tail=100 |
| 137 | +
|
| 138 | + - name: Stop Docker Compose services |
| 139 | + if: always() |
| 140 | + run: docker compose down -v |
| 141 | + |
| 142 | + - name: Create Pull Request |
| 143 | + uses: peter-evans/create-pull-request@v7 |
| 144 | + with: |
| 145 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + commit-message: "chore: Regenerate API client" |
| 147 | + branch: ${{ inputs.branch_name }} |
| 148 | + delete-branch: true |
| 149 | + title: ${{ inputs.pr_title }} |
| 150 | + body: | |
| 151 | + ## Summary |
| 152 | + This PR regenerates the API client from the latest OpenAPI schema and updates VCR cassettes. |
| 153 | +
|
| 154 | + ## Changes |
| 155 | + - Regenerated API client from latest OpenAPI schema |
| 156 | + - Updated VCR cassette fixtures to match current API responses |
| 157 | +
|
| 158 | + ## Test Plan |
| 159 | + - [x] Tests passed against live GoodData instance |
| 160 | + - [ ] Review API client changes |
| 161 | + - [ ] Review cassette changes for expected API modifications |
| 162 | + labels: | |
| 163 | + automated |
| 164 | + api-client |
0 commit comments