feat: content moderation validators (#7293) #68
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
| name: API client release | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - .github/workflows/api-client-release.yml | |
| - packages/api-client/** | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| release: | |
| if: github.repository_owner == 'modrinth' && github.ref == 'refs/heads/main' | |
| # npm Trusted Publishing requires a GitHub-hosted runner. | |
| runs-on: ubuntu-latest | |
| env: | |
| FORCE_COLOR: 3 | |
| PACKAGE_DIR: packages/api-client | |
| PACKAGE_NAME: '@modrinth/api-client' | |
| BUMP_TYPE: minor | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for api-client changes | |
| id: changes | |
| run: | | |
| if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| if git diff --quiet "${{ github.event.before }}" "$GITHUB_SHA" -- "$PACKAGE_DIR"; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Setup Node | |
| if: steps.changes.outputs.changed == 'true' | |
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | |
| with: | |
| node-version-file: .nvmrc | |
| registry-url: https://registry.npmjs.org | |
| - name: Enable Corepack | |
| if: steps.changes.outputs.changed == 'true' | |
| run: corepack enable | |
| - name: Get pnpm store path | |
| if: steps.changes.outputs.changed == 'true' | |
| id: pnpm-store | |
| run: echo "store-path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT" | |
| - name: Restore pnpm cache | |
| if: steps.changes.outputs.changed == 'true' | |
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | |
| with: | |
| path: ${{ steps.pnpm-store.outputs.store-path }} | |
| key: pnpm-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| pnpm-cache- | |
| - name: Install dependencies | |
| if: steps.changes.outputs.changed == 'true' | |
| run: pnpm install --frozen-lockfile --filter @modrinth/api-client... | |
| - name: Resolve release version | |
| if: steps.changes.outputs.changed == 'true' | |
| id: version | |
| run: | | |
| CURRENT_VERSION_JSON="$(npm view "${PACKAGE_NAME}" version --json)" | |
| CURRENT_VERSION="$( | |
| jq -nr \ | |
| --argjson version "$CURRENT_VERSION_JSON" \ | |
| 'if ($version | type) == "array" then $version[-1] else $version end' | |
| )" | |
| NEXT_VERSION="$( | |
| jq -nr \ | |
| --arg version "$CURRENT_VERSION" \ | |
| --arg bump "$BUMP_TYPE" ' | |
| def semver: | |
| capture("^(?<major>[0-9]+)\\.(?<minor>[0-9]+)\\.(?<patch>[0-9]+)$") | |
| | with_entries(.value |= tonumber); | |
| ($version | semver) as $current | |
| | if $bump == "major" then "\($current.major + 1).0.0" | |
| elif $bump == "minor" then "\($current.major).\($current.minor + 1).0" | |
| elif $bump == "patch" then "\($current.major).\($current.minor).\($current.patch + 1)" | |
| else error("Unsupported bump type: \($bump)") | |
| end | |
| ' | |
| )" | |
| PACKAGE_JSON="$(mktemp)" | |
| jq --tab --arg version "$NEXT_VERSION" '.version = $version' "$PACKAGE_DIR/package.json" > "$PACKAGE_JSON" | |
| mv "$PACKAGE_JSON" "$PACKAGE_DIR/package.json" | |
| echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "published_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Build api-client | |
| if: steps.changes.outputs.changed == 'true' | |
| run: pnpm --filter @modrinth/api-client build | |
| - name: Check package contents | |
| if: steps.changes.outputs.changed == 'true' | |
| working-directory: packages/api-client | |
| run: pnpm pack --dry-run | |
| - name: Publish api-client | |
| if: steps.changes.outputs.changed == 'true' | |
| working-directory: packages/api-client | |
| run: pnpm publish --access public --provenance --no-git-checks |