|
| 1 | +# yaml-language-server: $schema=https://www.schemastore.org/github-workflow.json |
| 2 | +name: Regenerate |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + version: |
| 8 | + description: Spec version (e.g. 1.2.3) |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + asset_url: |
| 12 | + description: GitHub API URL for the spec tarball release asset |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + spec_file: |
| 16 | + description: Spec filename inside the released spec tarball |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + |
| 20 | +jobs: |
| 21 | + regenerate: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + pull-requests: write |
| 26 | + env: |
| 27 | + SPEC_VERSION: ${{ github.event.inputs.version }} |
| 28 | + ASSET_URL: ${{ github.event.inputs.asset_url }} |
| 29 | + SPEC_FILE: ${{ github.event.inputs.spec_file || 'upcloud-public-openapi.json' }} |
| 30 | + |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 33 | + with: |
| 34 | + ref: v3-dev |
| 35 | + fetch-depth: 1 |
| 36 | + |
| 37 | + - name: Setup uv |
| 38 | + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 |
| 39 | + with: |
| 40 | + python-version: 3.14 |
| 41 | + |
| 42 | + - name: Download OpenAPI Spec |
| 43 | + env: |
| 44 | + SPECS_ACCESS_PAT: ${{ secrets.SPECS_ACCESS_PAT }} |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | +
|
| 48 | + if [ -z "$SPEC_VERSION" ]; then |
| 49 | + echo "ERROR: Missing workflow_dispatch input: version" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + if [ -z "$ASSET_URL" ]; then |
| 54 | + echo "ERROR: Missing asset_url" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +
|
| 58 | + if [ -z "$SPEC_FILE" ]; then |
| 59 | + echo "ERROR: Missing spec_file" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +
|
| 63 | + : "${SPECS_ACCESS_PAT:?ERROR: SPECS_ACCESS_PAT secret is not set}" |
| 64 | +
|
| 65 | + echo "Spec version: $SPEC_VERSION" |
| 66 | + echo "Spec file: $SPEC_FILE" |
| 67 | + echo "Downloading from ASSET_URL='$ASSET_URL'" |
| 68 | +
|
| 69 | + mkdir -p generator/openapi |
| 70 | +
|
| 71 | + curl --fail -L \ |
| 72 | + --retry 5 \ |
| 73 | + --retry-all-errors \ |
| 74 | + --retry-delay 2 \ |
| 75 | + -H "Authorization: Bearer $SPECS_ACCESS_PAT" \ |
| 76 | + -H "Accept: application/octet-stream" \ |
| 77 | + "$ASSET_URL" \ |
| 78 | + -o spec.tar.gz |
| 79 | +
|
| 80 | + echo "Extracting spec" |
| 81 | + rm -rf /tmp/spec-extract |
| 82 | + mkdir -p /tmp/spec-extract generator/openapi |
| 83 | +
|
| 84 | + if ! tar -tzf spec.tar.gz | grep -Fx "$SPEC_FILE" >/dev/null; then |
| 85 | + echo "ERROR: $SPEC_FILE not found in downloaded tarball" |
| 86 | + tar -tzf spec.tar.gz |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | +
|
| 90 | + tar -xzf spec.tar.gz -C /tmp/spec-extract "$SPEC_FILE" |
| 91 | + mv "/tmp/spec-extract/$SPEC_FILE" generator/openapi/spec.json |
| 92 | +
|
| 93 | + if [ ! -f generator/openapi/spec.json ]; then |
| 94 | + echo "ERROR: spec.json not found after extraction" |
| 95 | + find generator/openapi -maxdepth 2 -type f |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | +
|
| 99 | + - name: Run generator |
| 100 | + run: | |
| 101 | + chmod +x generator/scripts/generate.sh |
| 102 | + generator/scripts/generate.sh |
| 103 | +
|
| 104 | + - name: Update lockfile |
| 105 | + run: uv lock |
| 106 | + |
| 107 | + - name: Create PR |
| 108 | + uses: peter-evans/create-pull-request@v7 |
| 109 | + with: |
| 110 | + commit-message: "chore: regenerate SDK from spec ${{ env.SPEC_VERSION }}" |
| 111 | + branch: "regen/${{ env.SPEC_VERSION }}" |
| 112 | + title: "Regenerate SDK (${{ env.SPEC_VERSION }})" |
| 113 | + base: v3-dev |
| 114 | + body: > |
| 115 | + Automated regeneration for spec version |
| 116 | + `${{ env.SPEC_VERSION }}`. |
0 commit comments