Skip to content

Commit 58768a6

Browse files
authored
Merge branch 'main' into np-gm-1107
2 parents a8a99c9 + f9d1cb5 commit 58768a6

File tree

164 files changed

+8877
-1271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+8877
-1271
lines changed

.circleci/config.yml

Lines changed: 3 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ references:
6767
- packages
6868

6969
restore_node_modules: &restore_node_modules
70-
attach_workspace:
70+
attach_workspace: #The attach_workspace copies and re-creates the entire workspace content when it runs.
7171
at: ~/repo
7272

7373
build_all_packages: &build_all_packages
7474
run:
7575
name: Build All Packages
7676
command: yarn build
7777

78-
set_git_user: &set_git_user
78+
set_git_user: &set_git_user # move to yarn action maybe
7979
run:
8080
name: Set git user
8181
command: |
@@ -111,35 +111,13 @@ jobs:
111111
checkout_code:
112112
<<: *default_env
113113
steps:
114-
- checkout
114+
- checkout # circle keyword
115115
- *set_npm_token
116116
- *restore_yarn_cache
117117
- run: yarn --production=false --frozen-lockfile
118118
- *save_yarn_cache
119119
- *save_node_modules
120120

121-
tests:
122-
<<: *default_env
123-
resource_class: large
124-
steps:
125-
- checkout
126-
- *restore_node_modules
127-
- *restore_nx_cache
128-
- *build_all_packages
129-
- run:
130-
name: Run test suite
131-
command: |
132-
yarn test --parallel=4 --ci --coverage -- --runInBand
133-
environment:
134-
JEST_JUNIT_OUTPUT_DIR: /tmp/test-results/junit
135-
JEST_JUNIT_ADD_FILE_ATTRIBUTE: 'true'
136-
- *save_nx_cache
137-
- store_test_results:
138-
path: /tmp/test-results
139-
- store_artifacts:
140-
path: /tmp/test-results
141-
destination: test-results
142-
143121
publish:
144122
<<: *default_env
145123
resource_class: large
@@ -176,92 +154,6 @@ jobs:
176154
- *save_nx_cache
177155
- *save_webpack_cache
178156

179-
deploy_alpha:
180-
<<: *default_env
181-
resource_class: large
182-
steps:
183-
- *skip_if_not_pr
184-
- *skip_on_automated_commit
185-
- *set_git_user
186-
- checkout
187-
- *restore_node_modules
188-
- *restore_nx_cache
189-
- *restore_webpack_cache
190-
- *build_all_packages
191-
- run:
192-
name: build storybook
193-
command: yarn nx run styleguide:build-storybook
194-
- *save_nx_cache
195-
- *save_webpack_cache
196-
- run:
197-
name: deploy
198-
command: |
199-
DEPLOY_MESSAGE="User: ${CIRCLE_USERNAME} Project: ${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} Pull Request: ${CIRCLE_PULL_REQUEST}"
200-
npx [email protected] deploy --message "${DEPLOY_MESSAGE}" --dir dist/storybook/styleguide --json --filter @codecademy/styleguide > .deploy-output
201-
- setup_remote_docker
202-
- run: docker pull cloudposse/github-commenter:0.5.0-58
203-
- run:
204-
name: comment
205-
command: |
206-
export DEPLOY_OUTPUT="$(cat .deploy-output)"
207-
echo $DEPLOY_OUTPUT
208-
DEPLOY_URL=$(echo "console.log(JSON.parse(process.env.DEPLOY_OUTPUT).deploy_url)" | node -)
209-
LOGS_URL=$(echo "console.log(JSON.parse(process.env.DEPLOY_OUTPUT).logs)" | node -)
210-
COMMENT_MSG="<p><a href="${DEPLOY_URL}">${DEPLOY_URL}</a></p><p><a href="${LOGS_URL}">Deploy Logs</a></p>"
211-
if [ -z "$DEPLOY_OUTPUT" ]
212-
then
213-
echo "No deploy output found, will not add PR comment"
214-
else
215-
docker run --rm \
216-
-e GITHUB_TOKEN \
217-
-e GITHUB_OWNER="${CIRCLE_PROJECT_USERNAME}" \
218-
-e GITHUB_REPO="${CIRCLE_PROJECT_REPONAME}" \
219-
-e GITHUB_COMMENT_TYPE=pr \
220-
-e GITHUB_PR_ISSUE_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}" \
221-
-e GITHUB_COMMENT_TEMPLATE='<p>🚀 Styleguide deploy preview ready!</p>{{.}}<!--ALPHA_DEPLOY_COMMENT-->' \
222-
-e GITHUB_DELETE_COMMENT_REGEX="ALPHA_DEPLOY_COMMENT" \
223-
-e GITHUB_COMMENT="${COMMENT_MSG}" \
224-
cloudposse/github-commenter:0.5.0-58
225-
fi
226-
227-
publish_alpha:
228-
<<: *default_env
229-
resource_class: large
230-
steps:
231-
- *skip_if_not_pr
232-
- *skip_on_automated_commit
233-
- *set_git_user
234-
- checkout
235-
- *restore_node_modules
236-
- *set_npm_token
237-
- *restore_nx_cache
238-
- *build_all_packages
239-
- *save_nx_cache
240-
- run:
241-
name: lerna publish (alpha)
242-
command: yarn lerna publish --exact --yes --include-merged-tags --no-push --no-git-reset --conventional-commits --conventional-prerelease --preid=alpha.${CIRCLE_SHA1:0:6} --dist-tag=alpha.${CIRCLE_SHA1:0:6}
243-
- setup_remote_docker
244-
- run: docker pull cloudposse/github-commenter:0.5.0-58
245-
- run:
246-
name: Comment
247-
command: |
248-
ALPHA_PACKAGES="$(yarn lerna ll --parseable | grep alpha || true)"
249-
if [ -z "$ALPHA_PACKAGES" ]
250-
then
251-
echo "No alpha published packages found, will not add PR comment"
252-
else
253-
docker run --rm \
254-
-e GITHUB_TOKEN \
255-
-e GITHUB_OWNER="${CIRCLE_PROJECT_USERNAME}" \
256-
-e GITHUB_REPO="${CIRCLE_PROJECT_REPONAME}" \
257-
-e GITHUB_COMMENT_TYPE=pr \
258-
-e GITHUB_PR_ISSUE_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}" \
259-
-e GITHUB_COMMENT_TEMPLATE='<h3>📬Published Alpha Packages:</h3><pre>{{$x := splitList "\n" .}}{{range $x}}{{$y := split ":" .}}{{printf "%s@%v<br/>" $y._1 $y._2}}{{end}}</pre><!--LERNA_VERSION_COMMENT-->' \
260-
-e GITHUB_DELETE_COMMENT_REGEX="LERNA_VERSION_COMMENT" \
261-
-e GITHUB_COMMENT="${ALPHA_PACKAGES}" \
262-
cloudposse/github-commenter:0.5.0-58
263-
fi
264-
265157
workflows:
266158
version: 2
267159
build-test:
@@ -272,23 +164,12 @@ workflows:
272164
- checkout_code:
273165
requires:
274166
- queue/block_workflow
275-
- tests:
276-
requires:
277-
- checkout_code
278167
- publish:
279168
requires:
280169
- checkout_code
281170
filters:
282171
branches:
283172
only: main
284-
- publish_alpha:
285-
filters:
286-
branches:
287-
ignore:
288-
- main
289-
- gh-pages
290-
requires:
291-
- checkout_code
292173

293174
deploy:
294175
jobs:
@@ -304,11 +185,3 @@ workflows:
304185
filters:
305186
branches:
306187
only: main
307-
- deploy_alpha:
308-
filters:
309-
branches:
310-
ignore:
311-
- main
312-
- gh-pages
313-
requires:
314-
- checkout_code
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'Set Git User'
2+
description: 'Set git user configuration for automated commits'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Set git user
8+
shell: bash
9+
run: |
10+
git config --global user.email "[email protected]"
11+
git config --global user.name "codecademydev"
12+
git config --global push.default current
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'Set NPM Token'
2+
description: 'Set NPM authentication token in .npmrc file'
3+
4+
inputs:
5+
token-secret:
6+
description: 'Name of the GitHub secret containing the NPM token'
7+
required: true
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Set npm token
13+
shell: bash
14+
run: |
15+
echo "//registry.npmjs.org/:_authToken=${{ inputs.token-secret }}" > .npmrc
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Skip Automated Commits'
2+
description: 'Skip workflow execution if triggered by automated commit messages'
3+
4+
inputs:
5+
ignore-commit-message:
6+
description: 'Commit message pattern to ignore (e.g., chore(release): publish)'
7+
required: true
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Skip build from automated commit
13+
id: check-commit
14+
shell: bash
15+
run: |
16+
COMMIT_MESSAGE=$(git log --format=oneline -n 1 HEAD)
17+
echo "Build started due to commit with message $COMMIT_MESSAGE, blocking builds started by ${{ inputs.ignore-commit-message }}"
18+
if [[ $COMMIT_MESSAGE == *"${{ inputs.ignore-commit-message }}"* ]]; then
19+
echo "Skipping build due to automated commit"
20+
exit 0
21+
fi
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 'Sticky Pull Request Comment'
2+
description: 'Post a sticky comment to a pull request with customizable content'
3+
4+
inputs:
5+
github-token:
6+
description: 'GitHub token for authentication'
7+
required: true
8+
header:
9+
description: 'Header text for the comment'
10+
required: true
11+
message:
12+
description: 'Message content for the comment'
13+
required: true
14+
recreate:
15+
description: 'Whether to recreate the comment on each run'
16+
required: false
17+
default: 'true'
18+
19+
runs:
20+
using: 'composite'
21+
steps:
22+
- name: Comment with sticky pull request comment
23+
uses: marocchino/sticky-pull-request-comment@67d0dec7b07ed060a405f9b2a64b8ab319fdd7db
24+
with:
25+
GITHUB_TOKEN: ${{ inputs.github-token }}
26+
header: ${{ inputs.header }}
27+
recreate: ${{ inputs.recreate }}
28+
message: ${{ inputs.message }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Validate Pull Request Context'
2+
description: 'Ensure the workflow is running in a pull request context'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Ensure workflow is associated with a pull request
8+
shell: bash
9+
run: |
10+
if [[ -z "${{ github.event.pull_request.number }}" ]]; then
11+
echo "This workflow is not associated with a pull request; exiting"
12+
exit 1
13+
fi

.github/actions/yarn/action.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: 'Setup Node & yarn'
2+
description: 'Setup a NodeJS environment, install deps, & builds packages'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Setup Node.js
8+
uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610
9+
with:
10+
node-version-file: .nvmrc
11+
12+
- name: Install dependencies
13+
shell: bash
14+
run: yarn --production=false --frozen-lockfile

.github/workflows/deploy-alpha.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Deploy Storybook Preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
env:
8+
NODE_VERSION: '22.13.1'
9+
NODE_OPTIONS: '--max_old_space_size=8196'
10+
NX_CLOUD: false
11+
IGNORE_COMMIT_MESSAGE: 'chore(release): publish'
12+
13+
permissions:
14+
id-token: write
15+
contents: read
16+
pull-requests: write
17+
issues: write
18+
19+
jobs:
20+
deploy-alpha:
21+
runs-on: ubuntu-22.04
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Setup and Build
28+
id: setup
29+
uses: ./.github/actions/yarn
30+
31+
- name: Add NPM auth token file
32+
uses: ./.github/actions/set-npm-token
33+
with:
34+
token-secret: ${{ secrets.NPM_TOKEN }}
35+
36+
- name: Ensure workflow is associated with a pull request
37+
uses: ./.github/actions/validate-pr-context
38+
39+
- name: Skip build from automated commit
40+
uses: ./.github/actions/skip-automated-commits
41+
with:
42+
ignore-commit-message: ${{ env.IGNORE_COMMIT_MESSAGE }}
43+
44+
- name: Set git user
45+
uses: ./.github/actions/set-git-user
46+
47+
- name: Build All Packages
48+
run: yarn build
49+
50+
- name: Build Storybook
51+
run: yarn nx run styleguide:build-storybook
52+
53+
- name: Configure Netlify CLI
54+
env:
55+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
56+
run: |
57+
cd packages/styleguide
58+
npx [email protected] link --id ${{ secrets.NETLIFY_SITE_ID }}
59+
60+
- name: Deploy to Netlify
61+
id: deploy
62+
env:
63+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
64+
run: |
65+
DEPLOY_MESSAGE="User: ${{ github.actor }} Project: ${{ github.repository }} Pull Request: ${{ github.event.pull_request.html_url }}"
66+
if npx [email protected] deploy --message "${DEPLOY_MESSAGE}" --dir dist/storybook/styleguide --filter @codecademy/styleguide --json > .deploy-output 2>&1; then
67+
DEPLOY_OUTPUT=$(cat .deploy-output)
68+
echo "deploy-output<<EOF" >> $GITHUB_OUTPUT
69+
echo "$DEPLOY_OUTPUT" >> $GITHUB_OUTPUT
70+
echo "EOF" >> $GITHUB_OUTPUT
71+
else
72+
echo "Deploy failed. Output:"
73+
cat .deploy-output
74+
exit 1
75+
fi
76+
77+
- name: Extract deployment URLs
78+
id: extract-urls
79+
if: steps.deploy.outputs.deploy-output
80+
run: |
81+
DEPLOY_OUTPUT="${{ steps.deploy.outputs.deploy-output }}"
82+
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -o 'deploy_url: [^,]*' | sed 's/deploy_url: //')
83+
LOGS_URL=$(echo "$DEPLOY_OUTPUT" | grep -o 'logs: [^,]*' | sed 's/logs: //')
84+
echo "deploy-url=$DEPLOY_URL" >> $GITHUB_OUTPUT
85+
echo "logs-url=$LOGS_URL" >> $GITHUB_OUTPUT
86+
87+
- name: Comment with deployment preview
88+
uses: ./.github/actions/sticky-comment
89+
if: steps.extract-urls.outputs.deploy-url
90+
with:
91+
github-token: ${{ secrets.GITHUB_TOKEN }}
92+
header: Styleguide Deploy Preview
93+
message: |
94+
🚀 Styleguide deploy preview ready!
95+
96+
**Preview URL:** [${{ steps.extract-urls.outputs.deploy-url }}](${{ steps.extract-urls.outputs.deploy-url }})
97+
**Deploy Logs:** [${{ steps.extract-urls.outputs.logs-url }}](${{ steps.extract-urls.outputs.logs-url }})

0 commit comments

Comments
 (0)