fix(ci): actually this time #1630
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on: | |
| push: | |
| pull_request: | |
| workflow_dispatch: | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/cache@v4 | |
| with: | |
| key: pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: pnpm- | |
| path: | | |
| ~/.pnpm-store | |
| ~/.cache/pnpm | |
| **/node_modules | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - uses: oven-sh/setup-bun@v2 | |
| - run: pnpm install | |
| - if: github.event_name == 'push' | |
| run: | | |
| changes=$(git diff --name-only --diff-filter=d "${{ github.event.commits[0].id }}~1" "${{ github.event.commits[0].id }}") | |
| { | |
| echo 'changes<<eof_${{ github.run_id }}' | |
| echo "$changes" | |
| echo 'eof_${{ github.run_id }}' | |
| } >> $GITHUB_ENV | |
| - if: github.event_name == 'pull_request' | |
| run: | | |
| changes=$(git diff --name-only --diff-filter=d "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}") | |
| { | |
| echo 'changes<<eof_${{ github.run_id }}' | |
| echo "$changes" | |
| echo 'eof_${{ github.run_id }}' | |
| } >> $GITHUB_ENV | |
| - name: lint changed files | |
| if: env.changes != '' | |
| run: | | |
| pattern=$(echo "${{ env.changes }}" | tr '\n' '|' | sed 's/|$//') | |
| pnpm run lint-ci 2>&1 | grep -E "$pattern" || true | |
| exit ${PIPESTATUS[0]:-1} | |
| - name: lint files | |
| if: env.changes == '' | |
| continue-on-error: true | |
| run: pnpm run lint-ci | |
| bundle: | |
| runs-on: ubuntu-latest | |
| needs: lint | |
| strategy: | |
| matrix: | |
| format: [yaml, json] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/cache@v4 | |
| with: | |
| key: pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: pnpm- | |
| path: | | |
| ~/.pnpm-store | |
| ~/.cache/pnpm | |
| **/node_modules | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - uses: oven-sh/setup-bun@v2 | |
| - run: pnpm install | |
| - run: pnpm bundle --ext ${{ matrix.format }} | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: openapi.${{ matrix.format }} | |
| path: dist/openapi.${{ matrix.format }} | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: bundle | |
| if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, '[dry]') | |
| outputs: | |
| release: ${{ steps.data.outputs.release }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/cache@v4 | |
| with: | |
| key: pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: pnpm- | |
| path: | | |
| ~/.pnpm-store | |
| ~/.cache/pnpm | |
| **/node_modules | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - uses: oven-sh/setup-bun@v2 | |
| - run: pnpm install | |
| - uses: actions/download-artifact@v5 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - id: metadata | |
| run: | | |
| version=$(jq -r '.info.version' dist/openapi.json) | |
| echo "version=$version" >> $GITHUB_ENV | |
| version_sha=$( | |
| git rev-list -n 1 "v$version" 2>/dev/null \ | |
| || git rev-list -n 1 "release/$version" 2>/dev/null \ | |
| || echo "" | |
| ) | |
| echo "version_sha=$version_sha" >> $GITHUB_ENV | |
| echo "prerelease=$(test -z "$version_sha" && echo false || echo true)" >> $GITHUB_ENV | |
| - name: create release | |
| if: env.prerelease == 'false' | |
| run: gh release create v${{ env.version }} dist/* --generate-notes | |
| - name: create release (nightly) | |
| if: env.prerelease == 'true' | |
| run: | | |
| version=$(pnpm semver ${{ env.version }} -i)-nightly.$(git rev-list --count "${{ env.version_sha }}"..HEAD) | |
| echo "version=$version" >> $GITHUB_ENV | |
| jq --arg v "$version" '.info.version = $v' dist/openapi.json > dist/.openapi.json && mv dist/.openapi.json dist/openapi.json | |
| yq eval ".info.version = \"$version\"" -i dist/openapi.yaml | |
| gh release create v$version dist/* \ | |
| --generate-notes \ | |
| --prerelease | |
| - id: data | |
| run: | | |
| release=$(gh release view v${{ env.version }} --json id,tagName,url,isPrerelease,assets | jq -c '{ | |
| id, | |
| url, | |
| version: \"${{ env.version }}\" | |
| prerelease: .isPrerelease, | |
| artifacts: ( | |
| .assets | |
| | map({ (.name): .url }) | |
| | add | |
| ) | |
| }') | |
| echo "release=$release" >> $GITHUB_OUTPUT | |
| release_dispatch: | |
| runs-on: ubuntu-latest | |
| needs: release | |
| strategy: | |
| matrix: | |
| repository: | |
| - vrchatapi-javascript | |
| - vrchatapi-csharp | |
| - vrchatapi-python | |
| - vrchatapi-java | |
| - vrchatapi-rust | |
| - vrchatapi-dart | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - run: | | |
| jq -n --argjson payload "$release" '{ event_type: "release", client_payload: $payload }' \ | |
| | gh api repos/{owner}/$repository/dispatches -X POST -i --input - | |
| env: | |
| repository: ${{ matrix.repository }} | |
| release: ${{ needs.release.outputs.release }} | |
| GH_TOKEN: ${{ secrets.RELEASE_DISPATCH_TOKEN }} |