|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: |
| 5 | + - v2 |
| 6 | + |
| 7 | +# Ensure scripts are run with pipefail. See: |
| 8 | +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference |
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: bash |
| 12 | + |
| 13 | +jobs: |
| 14 | + tests: |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + os: |
| 19 | + - ubuntu-latest |
| 20 | + - windows-latest |
| 21 | + - macos-latest |
| 22 | + |
| 23 | + runs-on: ${{ matrix.os }} |
| 24 | + |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 27 | + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 |
| 28 | + with: |
| 29 | + node-version: "18.x" |
| 30 | + - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 |
| 31 | + |
| 32 | + - run: pnpm install |
| 33 | + |
| 34 | + # Grab localizations |
| 35 | + - run: pnpm docs-sync pull microsoft/TypeScript-Website-localizations#main 1 |
| 36 | + |
| 37 | + # Build the packages |
| 38 | + - run: pnpm bootstrap |
| 39 | + - run: pnpm build |
| 40 | + |
| 41 | + # Verify it compiles |
| 42 | + - run: pnpm build-site |
| 43 | + |
| 44 | + - uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 |
| 45 | + if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest' |
| 46 | + with: |
| 47 | + name: site |
| 48 | + path: packages/typescriptlang-org/public |
| 49 | + |
| 50 | + # Run all the package's tests |
| 51 | + - run: pnpm test |
| 52 | + |
| 53 | + # danger for PR builds |
| 54 | + - if: github.event_name == 'pull_request' && github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id && matrix.os == 'ubuntu-latest' |
| 55 | + run: "pnpm danger ci" |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - run: | |
| 60 | + git add . |
| 61 | + if ! git diff --staged --exit-code --quiet; then |
| 62 | + echo "This PR is missing some generated changes. Please update locally or merge the patch artifact." |
| 63 | + echo "" |
| 64 | + git diff --staged |
| 65 | + git diff --staged > missing.patch |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + name: Check for uncommitted changes |
| 69 | + id: check-diff |
| 70 | + if: github.event_name == 'pull_request' |
| 71 | +
|
| 72 | + - name: Upload diff artifact |
| 73 | + if: ${{ failure() && steps.check-diff.conclusion == 'failure' }} |
| 74 | + uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 |
| 75 | + with: |
| 76 | + name: missing.patch |
| 77 | + path: missing.patch |
| 78 | + |
| 79 | + changesets: |
| 80 | + name: changesets |
| 81 | + runs-on: ubuntu-latest |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 84 | + with: |
| 85 | + fetch-depth: 0 |
| 86 | + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 |
| 87 | + with: |
| 88 | + node-version: 'lts/*' |
| 89 | + - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 |
| 90 | + |
| 91 | + - run: pnpm install |
| 92 | + |
| 93 | + - name: Check for missing changesets |
| 94 | + run: | |
| 95 | + PR_CHANGESETS=$(ls .changeset | (grep -v -E 'README\.md|config\.json' || true) | wc -l) |
| 96 | + MAIN_CHANGESETS=$(git ls-tree -r origin/v2 .changeset | (grep -v -E 'README\.md|config\.json' || true) | wc -l) |
| 97 | +
|
| 98 | + # If the PR has no changesets, but main has changesets, assume this is PR is a versioning PR and exit |
| 99 | + if [[ $PR_CHANGESETS -eq 0 && $MAIN_CHANGESETS -gt 0 ]]; then |
| 100 | + echo "This PR is a versioning PR, exiting" |
| 101 | + exit 0 |
| 102 | + fi |
| 103 | +
|
| 104 | + # git switch -c changesets-temp |
| 105 | + # git checkout origin/v2 -- <ignored files> |
| 106 | + pnpm changeset status --since=origin/v2 |
| 107 | +
|
| 108 | + required: |
| 109 | + runs-on: ubuntu-latest |
| 110 | + if: ${{ always() }} |
| 111 | + needs: |
| 112 | + - tests |
| 113 | + - changesets |
| 114 | + |
| 115 | + steps: |
| 116 | + - name: Check required jobs |
| 117 | + env: |
| 118 | + NEEDS: ${{ toJson(needs) }} |
| 119 | + run: | |
| 120 | + ! echo $NEEDS | jq -e 'to_entries[] | { job: .key, result: .value.result } | select(.result != "success")' |
0 commit comments