Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with TypeScript-Website @ 5e3aabd3 #203

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: CI
on:
pull_request:
branches:
- v2

# Ensure scripts are run with pipefail. See:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
defaults:
run:
shell: bash

jobs:
tests:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
with:
node-version: "18.x"
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- run: pnpm install

# Grab localizations
- run: pnpm docs-sync pull microsoft/TypeScript-Website-localizations#main 1

# Build the packages
- run: pnpm bootstrap
- run: pnpm build

# Verify it compiles
- run: pnpm build-site

- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
with:
name: site
path: packages/typescriptlang-org/public

# Run all the package's tests
- run: pnpm test

# danger for PR builds
- if: github.event_name == 'pull_request' && github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id && matrix.os == 'ubuntu-latest'
run: "pnpm danger ci"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: |
git add .
if ! git diff --staged --exit-code --quiet; then
echo "This PR is missing some generated changes. Please update locally or merge the patch artifact."
echo ""
git diff --staged
git diff --staged > missing.patch
exit 1
fi
name: Check for uncommitted changes
id: check-diff
if: github.event_name == 'pull_request'

- name: Upload diff artifact
if: ${{ failure() && steps.check-diff.conclusion == 'failure' }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: missing.patch
path: missing.patch

changesets:
name: changesets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
with:
node-version: 'lts/*'
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- run: pnpm install

- name: Check for missing changesets
run: |
PR_CHANGESETS=$(ls .changeset | (grep -v -E 'README\.md|config\.json' || true) | wc -l)
MAIN_CHANGESETS=$(git ls-tree -r origin/v2 .changeset | (grep -v -E 'README\.md|config\.json' || true) | wc -l)

# If the PR has no changesets, but main has changesets, assume this is PR is a versioning PR and exit
if [[ $PR_CHANGESETS -eq 0 && $MAIN_CHANGESETS -gt 0 ]]; then
echo "This PR is a versioning PR, exiting"
exit 0
fi

# git switch -c changesets-temp
# git checkout origin/v2 -- <ignored files>
pnpm changeset status --since=origin/v2

required:
runs-on: ubuntu-latest
if: ${{ always() }}
needs:
- tests
- changesets

steps:
- name: Check required jobs
env:
NEEDS: ${{ toJson(needs) }}
run: |
! echo $NEEDS | jq -e 'to_entries[] | { job: .key, result: .value.result } | select(.result != "success")'
71 changes: 71 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'Code Scanning - Action'

on:
push:
branches:
- v2
pull_request:
branches:
- v2
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '30 1 * * 0'

permissions:
contents: read

# Ensure scripts are run with pipefail. See:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
defaults:
run:
shell: bash

jobs:
CodeQL-Build:
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: ubuntu-latest
if: github.repository == 'microsoft/TypeScript-Website'

permissions:
# required for all workflows
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@1b549b9259bda1cb5ddde3b41741a82a2d15a841 # v3.28.13
with:
config-file: ./.github/codeql/codeql-configuration.yml
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@1b549b9259bda1cb5ddde3b41741a82a2d15a841 # v3.28.13

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# ✏️ If the Autobuild fails above, remove it and uncomment the following
# three lines and modify them (or add more) to build your code if your
# project uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@1b549b9259bda1cb5ddde3b41741a82a2d15a841 # v3.28.13
188 changes: 188 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
name: Deploy preview environment
on:
workflow_run:
workflows: [CI]
types: [completed]
workflow_dispatch:
inputs:
pr:
required: true
type: string
description: PR number
pull_request_target:
types: [labeled]

permissions:
contents: read
pull-requests: write
actions: read

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Get PR/workflow run info
id: get-info
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
console.dir(context, { depth: null });

let pr;
let workflowRun;
let isLabel = false;
switch (context.eventName) {
case "workflow_dispatch":
console.log("Workflow dispatch event");
pr = (await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: +context.payload.inputs.pr,
})).data;
break;
case "pull_request_target":
console.log("Pull request target event");
pr = context.payload.pull_request;
break;
case "workflow_run":
console.log("Workflow run event");
workflowRun = context.payload.workflow_run;
pr = workflowRun.pull_requests[0];
if (pr) {
console.log("PR found in workflow run");
// Reload the PR to get the labels.
pr = (await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
})).data;
} else {
const q = `is:pr is:open repo:${context.repo.owner}/${context.repo.repo} sha:${workflowRun.head_sha}`;
console.log(`PR not found in workflow run, searching for it with ${q}`);
// PRs sent from forks do not get the pull_requests field set.
// https://github.com/orgs/community/discussions/25220
const response = await github.rest.search.issuesAndPullRequests({ q });
if (response.data.items.length > 0) {
pr = response.data.items[0];
}
}
}

if (!pr) {
console.log("Could not find PR");
return null;
}

console.log(`Found PR ${pr.html_url}`);
console.dir(pr, { depth: null });

if (pr.state !== "open") {
console.log(`PR ${pr.number} is not open`);
return null;
}

if (!pr.labels.some((label) => label.name === "deploy-preview")) {
console.log(`PR ${pr.number} does not have the deploy-preview label`);
return null;
}

if (!workflowRun) {
console.log(`No workflow run found in event, searching for it with ${pr.head.sha}`);
try {
workflowRun = (await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "CI.yml",
head_sha: pr.head.sha,
per_page: 1,
})).data.workflow_runs[0];
} catch (e) {
console.log(e);
}
}

if (!workflowRun) {
console.log(`Could not find workflow run for PR ${pr.number}`);
return null;
}

console.log(`Found workflow run ${workflowRun.html_url}`);
console.dir(workflowRun, { depth: null });

try {
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: "microsoft",
repo: "TypeScript-Website",
run_id: workflowRun.id,
});
console.dir(artifacts, { depth: null });
if (!artifacts.data.artifacts.some(x => x.name === "site")) {
console.log("No artifact found in workflow run");
return null;
}
} catch (e) {
console.log(e);
return null;
}

const result = { pr: pr.number, runId: workflowRun.id };
console.log(result);
return result;

- name: Download site build from PR
if: ${{ steps.get-info.outputs.result != 'null' }}
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: site
path: site
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ fromJson(steps.get-info.outputs.result).runId }}

- name: Deploy
id: deploy
if: ${{ steps.get-info.outputs.result != 'null' }}
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PREVIEW }}
# Unsetting the repo token so we can control commenting ourselves.
# repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "site"
skip_app_build: true
production_branch: v2
deployment_environment: ${{ fromJson(steps.get-info.outputs.result).pr }}

- name: Comment on PR
if: ${{ steps.get-info.outputs.result != 'null' }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
PR_NUMBER: ${{ fromJson(steps.get-info.outputs.result).pr }}
SITE_URL: ${{ steps.deploy.outputs.static_web_app_url }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prefix = "Azure Static Web Apps: Your stage site is ready!";
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: +process.env.PR_NUMBER,
per_page: 100,
});

for (const comment of comments) {
if (comment.user?.login === "github-actions[bot]" && comment.body?.startsWith(prefix)) {
console.log(`Deleting comment ${comment.id}`);
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
});
}
}

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: +process.env.PR_NUMBER,
body: `${prefix} Visit it here: ${process.env.SITE_URL}`
});
2 changes: 2 additions & 0 deletions packages/documentation/copy/en/modules-reference/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ While it’s rare to need to mix imports and require calls in the same file, thi
#### Examples

```ts
// @Filename: main.ts
import x, { y, z } from "mod";
import mod = require("mod");
const dynamic = import("mod");
Expand All @@ -304,6 +305,7 @@ export default "default export";
```

```js
// @Filename: main.js
import x, { y, z } from "mod";
const mod = require("mod");
const dynamic = import("mod");
Expand Down