Skip to content

Commit 40b9e16

Browse files
authored
add deployment workflows for GitHub Pages (#2038)
* add workflows * change trigger to pull_request * remove duplciate workflow stage name * remove workflow trigger conditions * switch to experimental workflow * attempt restoring storybook environment * fix build trigger * apply correct storybook environment * add deployments to permissions * bump more permissions * add ref * another workaround * change target_url to make deployment appear * revert ref stuff
1 parent 8df9029 commit 40b9e16

File tree

10 files changed

+111
-148
lines changed

10 files changed

+111
-148
lines changed
Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,57 @@
11
name: Deploy
22
on:
3-
push:
4-
branches-ignore:
5-
- 'main'
6-
paths:
7-
- 'src/**'
8-
- 'docs/**'
9-
- '.github/workflows/deploy*.yml'
10-
- 'package.json'
3+
pull_request:
4+
5+
permissions:
6+
contents: write
7+
pages: write
8+
id-token: write
9+
deployments: write
10+
issues: write
11+
statuses: write
12+
checks: write
13+
1114
jobs:
12-
deploy-preview:
15+
deploy:
1316
if: ${{ github.repository == 'primer/css' }}
14-
name: Preview
17+
uses: primer/.github/.github/workflows/deploy_preview.yml@rezrah/add-outputs
18+
name: Deploy preview
19+
with:
20+
node_version: 14
21+
install: yarn
22+
build: yarn build:docs:preview
23+
output_dir: docs/public
24+
25+
deploy-storybook:
26+
if: ${{ github.repository == 'primer/css' }}
27+
name: Preview Storybook
1528
runs-on: ubuntu-latest
29+
needs: deploy
1630
steps:
1731
- uses: actions/checkout@v3
18-
- uses: chrnorm/deployment-action@v1.2.0
19-
name: Create GitHub deployment
20-
id: deployment
21-
with:
22-
token: ${{ secrets.GITHUB_TOKEN }}
23-
environment: Preview
32+
2433
- uses: chrnorm/deployment-action@v1.2.0
2534
name: Create GitHub deployment for storybook
2635
id: storybook
2736
with:
2837
token: ${{ secrets.GITHUB_TOKEN }}
2938
environment: Storybook Preview
39+
target_url: '${{ needs.deploy.outputs.deployment_url }}/storybook'
3040

31-
- name: Vercel Action
32-
uses: amondnet/vercel-action@v20
33-
id: vercel-action
34-
with:
35-
github-token: ${{ secrets.GITHUB_TOKEN }}
36-
vercel-token: ${{ secrets.VERCEL_TOKEN_SHARED }}
37-
github-comment: false
38-
vercel-org-id: ${{ secrets.VERCEL_ORG_ID_SHARED }}
39-
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
40-
41-
- name: Update deployment status (success)
42-
if: success()
43-
uses: chrnorm/deployment-status@v1.0.0
44-
with:
45-
token: ${{ secrets.GITHUB_TOKEN }}
46-
environment_url: ${{ steps.vercel-action.outputs.preview-url }}
47-
state: "success"
48-
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
49-
5041
- name: Update storybook deployment status (success)
5142
if: success()
5243
uses: chrnorm/deployment-status@v1.0.0
5344
with:
5445
token: ${{ secrets.GITHUB_TOKEN }}
55-
environment_url: '${{ steps.vercel-action.outputs.preview-url }}/css/storybook'
56-
state: "success"
46+
environment_url: '${{ needs.deploy.outputs.deployment_url }}/storybook'
47+
target_url: '${{ needs.deploy.outputs.deployment_url }}/storybook'
48+
state: 'success'
5749
deployment_id: ${{ steps.storybook.outputs.deployment_id }}
5850

59-
- name: Update deployment status (failure)
60-
if: failure()
61-
uses: chrnorm/deployment-status@v1.0.0
62-
with:
63-
token: ${{ secrets.GITHUB_TOKEN }}
64-
state: "failure"
65-
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
66-
6751
- name: Update storybook deployment status (failure)
6852
if: failure()
6953
uses: chrnorm/deployment-status@v1.0.0
7054
with:
7155
token: ${{ secrets.GITHUB_TOKEN }}
72-
state: "failure"
56+
state: 'failure'
7357
deployment_id: ${{ steps.storybook.outputs.deployment_id }}
74-

.github/workflows/deploy_production.yml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,40 @@ on:
88
- 'docs/**'
99
- '.github/workflows/deploy*.yml'
1010
- 'package.json'
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
1117
jobs:
12-
deploy:
13-
if: ${{ github.repository == 'primer/css' }}
14-
name: Production
18+
guard:
19+
name: Guard
1520
runs-on: ubuntu-latest
21+
outputs:
22+
# To avoid deploying documentation for unrelease changes, we check the number of changeset files.
23+
# If it's 0, we deploy.
24+
should_deploy: ${{ steps.changeset-count.outputs.change_count == 0 }}
1625
steps:
17-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@v2
1827

19-
# Check the number of changeset files, if it's 0 we deploy
2028
- id: changeset-count
21-
run: echo "::set-output name=CHANGE_COUNT::$(ls .changeset/*.md | grep -v README | wc -l | xargs)"
29+
run: echo "::set-output name=change_count::$(ls .changeset/*.md | grep -v README | wc -l | xargs)"
2230

23-
- if: ${{ steps.changeset-count.outputs.CHANGE_COUNT == 0 }}
24-
name: Vercel Action
25-
uses: amondnet/vercel-action@v20
26-
id: vercel-action
27-
with:
28-
github-token: ${{ secrets.GITHUB_TOKEN }}
29-
vercel-token: ${{ secrets.VERCEL_TOKEN_SHARED }}
30-
vercel-args: '--prod'
31-
github-comment: false
32-
vercel-org-id: ${{ secrets.VERCEL_ORG_ID_SHARED }}
33-
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
31+
# Log changeset count for debugging purposes
32+
- name: Log changeset count
33+
run: echo ${{ steps.changeset-count.outputs.change_count }}
34+
35+
# Log guard output for debugging purposes
36+
- name: Log guard output
37+
run: echo ${{ needs.guard.outputs.should_deploy }}
38+
deploy:
39+
if: ${{ github.repository == 'primer/css' && needs.guard.outputs.should_deploy == true }}
40+
name: Production
41+
needs: [guard]
42+
uses: primer/.github/.github/workflows/deploy_preview.yml@main
43+
with:
44+
node_version: 14
45+
install: yarn
46+
build: yarn build:docs
47+
output_dir: docs/public

DEVELOP.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,32 @@
33
If you've made it this far, **thank you**! We appreciate your contribution, and hope that this document helps you along the way. If you have any questions or problems, don't hesitate to [file an issue](https://github.com/primer/css/issues/new).
44

55
## Structure
6+
67
Primer CSS is published to [npm] as [@primer/css]. Each of Primer CSS's "modules" lives in a subfolder under `src/` with an `index.scss` in it. Generally speaking, the styles are divided into three primary themes:
78

8-
* **Core** styles (in `core/`) are common dependencies, which include support variables, native element and typography styles, buttons, navigation, tooltips, etc.
9-
* **Product** styles (in `product/`) are specific to github.com, and include components such as avatars, labels, markdown styles, popovers, and progress indicators.
10-
* **Marketing** styles (in `marketing/`) are specific to GitHub marketing efforts, including international and event-focused sites as well as the more design-heavy feature pages on github.com. Marketing styles include new colors and button styles, and extend the core typography and whitespace scales.
9+
- **Core** styles (in `core/`) are common dependencies, which include support variables, native element and typography styles, buttons, navigation, tooltips, etc.
10+
- **Product** styles (in `product/`) are specific to github.com, and include components such as avatars, labels, markdown styles, popovers, and progress indicators.
11+
- **Marketing** styles (in `marketing/`) are specific to GitHub marketing efforts, including international and event-focused sites as well as the more design-heavy feature pages on github.com. Marketing styles include new colors and button styles, and extend the core typography and whitespace scales.
1112

1213
### Paths
13-
Here's what you need to know about how the files are structured in both git and in the published npm module:
1414

15-
* In git, all of the SCSS source files live in the `src/` directory.
16-
* When published, all of the files in `src/` are "hoisted" to the package root so that you can import, say, utilities with:
15+
Here's what you need to know about how the files are structured in both git and in the published npm module:
1716

18-
```scss
19-
@import "@primer/css/utilities/index.scss";
20-
```
17+
- In git, all of the SCSS source files live in the `src/` directory.
18+
- When published, all of the files in `src/` are "hoisted" to the package root so that you can import, say, utilities with:
2119

22-
* All bundle interdependencies within Primer CSS are defined as relative imports (e.g. with `../`), so everything should work fine as long as the `@primer/css` directory is in one of your Sass include paths (i.e. `node_modules`).
20+
```scss
21+
@import '@primer/css/utilities/index.scss';
22+
```
2323

24+
- All bundle interdependencies within Primer CSS are defined as relative imports (e.g. with `../`), so everything should work fine as long as the `@primer/css` directory is in one of your Sass include paths (i.e. `node_modules`).
2425

2526
## Install
27+
2628
Run `npm install` to install the npm dependencies.
2729

2830
## Docs site
31+
2932
The Primer CSS docs are built with React using [Doctocat](https://primer.style/doctocat) and automatically deployed on every push to this repo with [Now]. You can run the server locally with:
3033

3134
```sh
@@ -35,41 +38,43 @@ npm start
3538
Then visit http://localhost:8000 to view the site.
3639

3740
### The docs directory
38-
The [docs directory](../docs/) contains all of the documentation files in our docs site. Files are nested in the `/content` folder.
3941

42+
The [docs directory](../docs/) contains all of the documentation files in our docs site. Files are nested in the `/content` folder.
4043

4144
### Code blocks
45+
4246
All `html` fenced code blocks in `src/**/*.md` will be rendered as stories and listed under the relevant module's name in the left-hand nav. File changes should trigger a live reload automatically (after a brief delay).
4347

4448
## Storybook
4549

46-
Primer CSS Storybook is used for designing and prototyping components. Stories are written in HTML and leverage the Storybook API for configuring conditional logic.
50+
Primer CSS Storybook is used for designing and prototyping components. Stories are written in HTML and leverage the Storybook API for configuring conditional logic.
4751

4852
```sh
4953
npm run storybook
5054
```
5155

5256
### The Storybook directory
57+
5358
Storybook configuration files live in [.storybook](../docs/.storybook). Addons and additional global config can be added to [main.js](../docs/.storybook/main.js) or [preview.js](../docs/.storybook/preview.js)
5459

5560
### Stories
61+
5662
Stories are individual `.jsx` or `.mdx` files that contain component HTML for prototyping, typically showcasing all possible variations of a component. Stories can be found in the [stories directory](../docs/src/stories/components) and are organized by component. Storybook will build and deploy a preview on any open Pull Request.
5763

5864
## Scripts
65+
5966
Our [`package.json`](package.json) houses a collection of [run-scripts] that we use to maintain, test, build, and publish Primer CSS. Run `npm run <script>` with any of the following values for `<script>`:
6067

61-
* `dist` runs `script/dist`, which creates CSS bundles of all the `index.scss` files in `src/`.
62-
* `check-links` runs a link checker on your local development server (`localhost:3000`, started with `npm start`).
63-
* `stylelint` lints the CSS source files.
64-
* `eslint` lints the JavaScript source files.
65-
* `now-build` and `now-start` are run on [Now] to build and start the docs site server. `now-test` runs them both in order.
66-
* `start` runs the documentation site locally (alias: `dev`).
67-
* `test` runs our test suite.
68-
* `storybook` runs storybook local development server.
68+
- `dist` runs `script/dist`, which creates CSS bundles of all the `index.scss` files in `src/`.
69+
- `check-links` runs a link checker on your local development server (`localhost:3000`, started with `npm start`).
70+
- `stylelint` lints the CSS source files.
71+
- `eslint` lints the JavaScript source files.
72+
- `start` runs the documentation site locally (alias: `dev`).
73+
- `test` runs our test suite.
74+
- `storybook` runs storybook local development server.
6975

7076
The above list may not always be up-to-date. You can list all of the available scripts by calling `npm run` with no other arguments.
7177

72-
7378
[@primer/css]: https://www.npmjs.com/package/@primer/css
7479
[run-scripts]: https://docs.npmjs.com/cli/run-script
7580
[now]: https://zeit.co/now

docs/.storybook/manager-head.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
"scripts": {
66
"clean": "gatsby clean",
77
"develop": "ln -sf ../dist . && gatsby develop -H 0.0.0.0",
8-
"build-content": "gatsby build --prefix-paths",
9-
"build": "./script/now-build.sh && ./script/build-storybook.sh",
108
"storybook": "NODE_ENV=test start-storybook -p 6006",
11-
"build-storybook": "./script/build-storybook.sh"
9+
"build:storybook": "script/build-storybook"
1210
},
1311
"dependencies": {
1412
"@babel/preset-react": "^7.16.7",

docs/script/build-storybook.sh renamed to docs/script/build-storybook

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/bin/bash
2-
2+
set -e
33
# Add base url to be able to serve static files
4-
echo '<base href="/css/storybook/" />' >> .storybook/manager-head.html
4+
if [ -n "$1" ]; then
5+
echo '<base href="/storybook/" />' >> .storybook/manager-head.html
6+
else
7+
echo '<base href="/css/storybook/" />' >> .storybook/manager-head.html
8+
fi
59

610
# Build storybook inside docs
711
./node_modules/.bin/build-storybook -o public/storybook -s public/static

docs/script/now-build.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"design-system"
2424
],
2525
"scripts": {
26+
"build:docs": "script/build-docs",
27+
"build:docs:preview": "script/build-docs preview",
2628
"dist": "script/dist.js",
2729
"dist:watch": "chokidar \"src/**/*.scss\" -c \"script/dist.js\"",
2830
"stylelint": "stylelint --quiet --rd 'src/**/*.scss'",
@@ -33,6 +35,7 @@
3335
"prepublishOnly": "script/prepublish",
3436
"start": "yarn dev",
3537
"dev": "cd docs && yarn && yarn develop",
38+
"postinstall": "cd docs && yarn",
3639
"pretest": "yarn dist && script/pretest",
3740
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
3841
"release": "changeset publish",

script/build-docs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash -e
2+
3+
# Build the base project so we can pull out the JSON data
4+
yarn dist
5+
cp -rf dist docs
6+
7+
# Now build the docs site using that data
8+
cd docs
9+
10+
if [ -n "$1" ]; then
11+
CI=true yarn gatsby build && yarn build:storybook preview
12+
else
13+
CI=true yarn gatsby build --prefix-paths && yarn build:storybook
14+
fi

vercel.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)