Skip to content

Commit 05c204e

Browse files
committed
merging all conflicts
2 parents ef02353 + a1a6517 commit 05c204e

File tree

8 files changed

+525
-2
lines changed

8 files changed

+525
-2
lines changed

.github/workflows/CI.yml

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
28+
with:
29+
node-version: "18.x"
30+
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
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@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
87+
with:
88+
node-version: 'lts/*'
89+
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.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")'

.github/workflows/codeql.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: 'Code Scanning - Action'
2+
3+
on:
4+
push:
5+
branches:
6+
- v2
7+
pull_request:
8+
branches:
9+
- v2
10+
schedule:
11+
# ┌───────────── minute (0 - 59)
12+
# │ ┌───────────── hour (0 - 23)
13+
# │ │ ┌───────────── day of the month (1 - 31)
14+
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
15+
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
16+
# │ │ │ │ │
17+
# │ │ │ │ │
18+
# │ │ │ │ │
19+
# * * * * *
20+
- cron: '30 1 * * 0'
21+
22+
permissions:
23+
contents: read
24+
25+
# Ensure scripts are run with pipefail. See:
26+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
27+
defaults:
28+
run:
29+
shell: bash
30+
31+
jobs:
32+
CodeQL-Build:
33+
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
34+
runs-on: ubuntu-latest
35+
if: github.repository == 'microsoft/TypeScript-Website'
36+
37+
permissions:
38+
# required for all workflows
39+
security-events: write
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
44+
45+
# Initializes the CodeQL tools for scanning.
46+
- name: Initialize CodeQL
47+
uses: github/codeql-action/init@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
48+
with:
49+
config-file: ./.github/codeql/codeql-configuration.yml
50+
# Override language selection by uncommenting this and choosing your languages
51+
# with:
52+
# languages: go, javascript, csharp, python, cpp, java
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below).
56+
- name: Autobuild
57+
uses: github/codeql-action/autobuild@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following
63+
# three lines and modify them (or add more) to build your code if your
64+
# project uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15

.github/workflows/deploy-preview.yml

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
name: Deploy preview environment
2+
on:
3+
workflow_run:
4+
workflows: [CI]
5+
types: [completed]
6+
workflow_dispatch:
7+
inputs:
8+
pr:
9+
required: true
10+
type: string
11+
description: PR number
12+
pull_request_target:
13+
types: [labeled]
14+
15+
permissions:
16+
contents: read
17+
pull-requests: write
18+
actions: read
19+
20+
jobs:
21+
deploy:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Get PR/workflow run info
25+
id: get-info
26+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
27+
with:
28+
script: |
29+
console.dir(context, { depth: null });
30+
31+
let pr;
32+
let workflowRun;
33+
let isLabel = false;
34+
switch (context.eventName) {
35+
case "workflow_dispatch":
36+
console.log("Workflow dispatch event");
37+
pr = (await github.rest.pulls.get({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
pull_number: +context.payload.inputs.pr,
41+
})).data;
42+
break;
43+
case "pull_request_target":
44+
console.log("Pull request target event");
45+
pr = context.payload.pull_request;
46+
break;
47+
case "workflow_run":
48+
console.log("Workflow run event");
49+
workflowRun = context.payload.workflow_run;
50+
pr = workflowRun.pull_requests[0];
51+
if (pr) {
52+
console.log("PR found in workflow run");
53+
// Reload the PR to get the labels.
54+
pr = (await github.rest.pulls.get({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
pull_number: pr.number,
58+
})).data;
59+
} else {
60+
const q = `is:pr is:open repo:${context.repo.owner}/${context.repo.repo} sha:${workflowRun.head_sha}`;
61+
console.log(`PR not found in workflow run, searching for it with ${q}`);
62+
// PRs sent from forks do not get the pull_requests field set.
63+
// https://github.com/orgs/community/discussions/25220
64+
const response = await github.rest.search.issuesAndPullRequests({ q });
65+
if (response.data.items.length > 0) {
66+
pr = response.data.items[0];
67+
}
68+
}
69+
}
70+
71+
if (!pr) {
72+
console.log("Could not find PR");
73+
return null;
74+
}
75+
76+
console.log(`Found PR ${pr.html_url}`);
77+
console.dir(pr, { depth: null });
78+
79+
if (pr.state !== "open") {
80+
console.log(`PR ${pr.number} is not open`);
81+
return null;
82+
}
83+
84+
if (!pr.labels.some((label) => label.name === "deploy-preview")) {
85+
console.log(`PR ${pr.number} does not have the deploy-preview label`);
86+
return null;
87+
}
88+
89+
if (!workflowRun) {
90+
console.log(`No workflow run found in event, searching for it with ${pr.head.sha}`);
91+
try {
92+
workflowRun = (await github.rest.actions.listWorkflowRuns({
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
workflow_id: "CI.yml",
96+
head_sha: pr.head.sha,
97+
per_page: 1,
98+
})).data.workflow_runs[0];
99+
} catch (e) {
100+
console.log(e);
101+
}
102+
}
103+
104+
if (!workflowRun) {
105+
console.log(`Could not find workflow run for PR ${pr.number}`);
106+
return null;
107+
}
108+
109+
console.log(`Found workflow run ${workflowRun.html_url}`);
110+
console.dir(workflowRun, { depth: null });
111+
112+
try {
113+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
114+
owner: "microsoft",
115+
repo: "TypeScript-Website",
116+
run_id: workflowRun.id,
117+
});
118+
console.dir(artifacts, { depth: null });
119+
if (!artifacts.data.artifacts.some(x => x.name === "site")) {
120+
console.log("No artifact found in workflow run");
121+
return null;
122+
}
123+
} catch (e) {
124+
console.log(e);
125+
return null;
126+
}
127+
128+
const result = { pr: pr.number, runId: workflowRun.id };
129+
console.log(result);
130+
return result;
131+
132+
- name: Download site build from PR
133+
if: ${{ steps.get-info.outputs.result != 'null' }}
134+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
135+
with:
136+
name: site
137+
path: site
138+
github-token: ${{ secrets.GITHUB_TOKEN }}
139+
run-id: ${{ fromJson(steps.get-info.outputs.result).runId }}
140+
141+
- name: Deploy
142+
id: deploy
143+
if: ${{ steps.get-info.outputs.result != 'null' }}
144+
uses: Azure/static-web-apps-deploy@v1
145+
with:
146+
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PREVIEW }}
147+
# Unsetting the repo token so we can control commenting ourselves.
148+
# repo_token: ${{ secrets.GITHUB_TOKEN }}
149+
action: "upload"
150+
app_location: "site"
151+
skip_app_build: true
152+
production_branch: v2
153+
deployment_environment: ${{ fromJson(steps.get-info.outputs.result).pr }}
154+
155+
- name: Comment on PR
156+
if: ${{ steps.get-info.outputs.result != 'null' }}
157+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
158+
env:
159+
PR_NUMBER: ${{ fromJson(steps.get-info.outputs.result).pr }}
160+
SITE_URL: ${{ steps.deploy.outputs.static_web_app_url }}
161+
with:
162+
github-token: ${{ secrets.GITHUB_TOKEN }}
163+
script: |
164+
const prefix = "Azure Static Web Apps: Your stage site is ready!";
165+
const comments = await github.paginate(github.rest.issues.listComments, {
166+
owner: context.repo.owner,
167+
repo: context.repo.repo,
168+
issue_number: +process.env.PR_NUMBER,
169+
per_page: 100,
170+
});
171+
172+
for (const comment of comments) {
173+
if (comment.user?.login === "github-actions[bot]" && comment.body?.startsWith(prefix)) {
174+
console.log(`Deleting comment ${comment.id}`);
175+
await github.rest.issues.deleteComment({
176+
owner: context.repo.owner,
177+
repo: context.repo.repo,
178+
comment_id: comment.id,
179+
});
180+
}
181+
}
182+
183+
await github.rest.issues.createComment({
184+
owner: context.repo.owner,
185+
repo: context.repo.repo,
186+
issue_number: +process.env.PR_NUMBER,
187+
body: `${prefix} Visit it here: ${process.env.SITE_URL}`
188+
});

0 commit comments

Comments
 (0)