.github/workflows/ci.yaml #1861
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: | |
| branches: | |
| - main | |
| pull_request: | |
| workflow_dispatch: | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - uses: pnpm/setup@v2 | |
| with: | |
| runtime: bun@latest | |
| cache: true | |
| - 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 | |
| - name: assert no unused paths | |
| if: env.changes != '' | |
| run: | | |
| status=0 | |
| mapfile -t expected <<< "$(yq -re '.paths | keys' openapi/components/paths/*.yaml | yq -r 'sort_by(.) | .[]')" | |
| mapfile -t actual <<< "$(yq -re 'sort_by(keys) | keys[]' openapi/components/paths.yaml)" | |
| for ((i = 0, j = 0; i < "${#expected[@]}"; i++)); do | |
| if [[ "${expected[$i]}" == "${actual[$j]}" ]]; then | |
| j=$((j + 1)) | |
| else | |
| status=2 | |
| echo "Missing path: ${expected[$i]}" >&2; | |
| fi | |
| done; | |
| if [[ "$status" -ne 0 ]]; then | |
| exit "$status" | |
| fi | |
| bundle: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: pnpm/setup@v2 | |
| with: | |
| runtime: bun@latest | |
| cache: true | |
| - run: bun --bun run bundle | |
| - uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const { readdir } = require("node:fs/promises"); | |
| const { resolve, dirname } = require("node:path"); | |
| const { DefaultArtifactClient } = require("@actions/artifact"); | |
| const artifact = new DefaultArtifactClient(); | |
| const files = await readdir("./dist"); | |
| const artifacts = await Promise.all(files.map(async (file) => { | |
| const pathname = resolve(`./dist/${file}`); | |
| return artifact.uploadArtifact(file, [pathname], dirname(pathname)); | |
| })); | |
| build_javascript: | |
| needs: bundle | |
| uses: vrchatapi/vrchatapi-javascript/.github/workflows/ci.yaml@ci/modernise-actions | |
| with: | |
| ref: ci/modernise-actions | |
| build_rust: | |
| needs: bundle | |
| uses: vrchatapi/vrchatapi-rust/.github/workflows/ci.yaml@ci/modernise-actions | |
| with: | |
| ref: ci/modernise-actions | |
| build_java: | |
| needs: bundle | |
| uses: vrchatapi/vrchatapi-java/.github/workflows/ci.yaml@ci/modernise-actions | |
| with: | |
| ref: ci/modernise-actions | |
| build_python: | |
| needs: bundle | |
| uses: vrchatapi/vrchatapi-python/.github/workflows/ci.yaml@ci/modernise-actions | |
| with: | |
| ref: ci/modernise-actions | |
| build_csharp: | |
| needs: bundle | |
| uses: vrchatapi/vrchatapi-csharp/.github/workflows/ci.yaml@ci/modernise-actions | |
| with: | |
| ref: ci/modernise-actions | |
| build_dart: | |
| needs: bundle | |
| uses: vrchatapi/vrchatapi-dart/.github/workflows/ci.yaml@ci/modernise-actions | |
| with: | |
| ref: ci/modernise-actions | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - lint | |
| - bundle | |
| if: ${{ !failure() && !cancelled() && github.ref == 'refs/heads/main' }} | |
| outputs: | |
| version: ${{ steps.metadata.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - uses: pnpm/setup@v2 | |
| with: | |
| runtime: bun@latest | |
| cache: true | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| path: dist | |
| pattern: openapi* | |
| merge-multiple: true | |
| - id: metadata | |
| run: | | |
| version=$(jq -r '.info.version' dist/openapi.json) | |
| version_sha=$( | |
| git rev-list -n 1 "v$version" 2>/dev/null \ | |
| || git rev-list -n 1 "release/$version" 2>/dev/null \ | |
| || echo "" | |
| ) | |
| if [ "$version_sha" == "" ]; then | |
| echo "prerelease=false" >> $GITHUB_ENV | |
| else | |
| echo "prerelease=true" >> $GITHUB_ENV | |
| version=$(pnpm semver $version -i)-nightly.$(git rev-list --count "$version_sha"..HEAD) | |
| fi | |
| echo "version=$version" >> $GITHUB_ENV | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| - 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: | | |
| jq --arg v "${{ env.version }}" '.info.version = $v' dist/openapi.json > dist/.openapi.json && mv dist/.openapi.json dist/openapi.json | |
| yq eval ".info.version = \"${{ env.version }}\"" -i dist/openapi.yaml | |
| gh release create v${{ env.version }} dist/* \ | |
| --generate-notes \ | |
| --prerelease | |
| release_dispatch: | |
| uses: ./.github/workflows/release_dispatch.yaml | |
| needs: release | |
| secrets: inherit | |
| with: | |
| version: ${{ needs.release.outputs.version }} |