Skip to content

Commit 0d90f0c

Browse files
committed
ci: Extract branch publishing into separate workflow
1 parent c8ac989 commit 0d90f0c

File tree

5 files changed

+102
-112
lines changed

5 files changed

+102
-112
lines changed

.github/actions/deploy-dir-as-branch/action.yml

-58
This file was deleted.

.github/workflows/canary.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ on:
77
- completed
88
env:
99
NODE_VERSION_USED_FOR_DEVELOPMENT: 17
10-
CI_WORKFLOW_ID: ${{github.event.workflow_run.id}}
1110
jobs:
1211
publish-canary:
1312
runs-on: ubuntu-latest
1413
name: Publish Canary
15-
if: ${{ github.event.workflow_run.event == 'pull_request' }}
14+
if: github.event.workflow_run.event == 'pull_request'
1615
steps:
1716
- name: Checkout repo
1817
uses: actions/checkout@v2
@@ -27,18 +26,17 @@ jobs:
2726
# 'registry-url' is required for 'npm publish'
2827
registry-url: 'https://registry.npmjs.org'
2928

30-
- name: Install Dependencies
31-
run: npm ci --ignore-scripts
32-
3329
- name: Download event.json
34-
run: gh run download "$CI_WORKFLOW_ID" -n event.json
30+
run: gh run download "$WORKFLOW_ID" -n event.json
3531
env:
3632
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
WORKFLOW_ID: ${{github.event.workflow_run.id}}
3734

3835
- name: Download NPM package artifact
39-
run: gh run download "$CI_WORKFLOW_ID" -n npmDist -D npmDist
36+
run: gh run download "$WORKFLOW_ID" -n npmDist -D npmDist
4037
env:
4138
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
WORKFLOW_ID: ${{github.event.workflow_run.id}}
4240

4341
- name: Modify NPM package to be canary release
4442
uses: actions/github-script@v5

.github/workflows/cd.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CD
2+
on:
3+
workflow_run:
4+
workflows:
5+
- CI
6+
types:
7+
- completed
8+
branches:
9+
- main
10+
jobs:
11+
deploy-to-npm-branch:
12+
name: Deploy to `npm` branch
13+
if: github.event.workflow_run.event == 'push'
14+
uses: ./.github/workflows/deploy-artifact-as-branch.yml
15+
with:
16+
workflow_id: ${{github.event.workflow_run.id}}
17+
artifact_name: npmDist
18+
target_branch: npm
19+
commit_message: "Deploy ${{github.event.workflow_run.head_sha}} to 'npm' branch"
20+
21+
deploy-to-deno-branch:
22+
name: Deploy to `deno` branch
23+
if: github.event.workflow_run.event == 'push'
24+
uses: ./.github/workflows/deploy-artifact-as-branch.yml
25+
with:
26+
workflow_id: ${{github.event.workflow_run.id}}
27+
artifact_name: denoDist
28+
target_branch: deno
29+
commit_message: "Deploy ${{github.event.workflow_run.head_sha}} to 'deno' branch"

.github/workflows/ci.yml

+17-47
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ jobs:
246246
path: ./npm-dist-diff.html
247247
if-no-files-found: ignore
248248

249-
build-npm-package:
250-
name: Build artifact with NPM package
249+
build-npm-dist:
250+
name: Build 'npmDist' artifact
251251
runs-on: ubuntu-latest
252252
needs: [test, fuzz, lint, integrationTests]
253253
steps:
@@ -268,52 +268,16 @@ jobs:
268268
- name: Build NPM package
269269
run: npm run build:npm
270270

271-
- name: Upload NPM package
271+
- name: Upload npmDist package
272272
uses: actions/upload-artifact@v2
273273
with:
274274
name: npmDist
275275
path: ./npmDist
276276

277-
deploy-to-npm-branch:
278-
name: Deploy to `npm` branch
277+
build-deno-dist:
278+
name: Build 'denoDist' artifact
279279
runs-on: ubuntu-latest
280-
if: |
281-
github.event_name == 'push' &&
282-
github.repository == 'graphql/graphql-js' &&
283-
github.ref == 'refs/heads/main'
284-
needs: [test, fuzz, lint, checkForCommonlyIgnoredFiles, integrationTests]
285-
steps:
286-
- name: Checkout repo
287-
uses: actions/checkout@v2
288-
with:
289-
persist-credentials: false
290-
291-
- name: Setup Node.js
292-
uses: actions/setup-node@v2
293-
with:
294-
cache: npm
295-
node-version: ${{ env.NODE_VERSION_USED_FOR_DEVELOPMENT }}
296-
297-
- name: Install Dependencies
298-
run: npm ci --ignore-scripts
299-
300-
- name: Build NPM package
301-
run: npm run build:npm
302-
303-
- name: Deploy to `npm` branch
304-
uses: ./.github/actions/deploy-dir-as-branch
305-
with:
306-
src_dir: npmDist
307-
target_branch: npm
308-
309-
deploy-to-deno-branch:
310-
name: Deploy to `deno` branch
311-
runs-on: ubuntu-latest
312-
if: |
313-
github.event_name == 'push' &&
314-
github.repository == 'graphql/graphql-js' &&
315-
github.ref == 'refs/heads/main'
316-
needs: [test, fuzz, lint, checkForCommonlyIgnoredFiles, integrationTests]
280+
needs: [test, fuzz, lint, integrationTests]
317281
steps:
318282
- name: Checkout repo
319283
uses: actions/checkout@v2
@@ -332,13 +296,13 @@ jobs:
332296
- name: Build Deno package
333297
run: npm run build:deno
334298

335-
- name: Deploy to `deno` branch
336-
uses: ./.github/actions/deploy-dir-as-branch
299+
- name: Upload denoDist package
300+
uses: actions/upload-artifact@v2
337301
with:
338-
src_dir: denoDist
339-
target_branch: deno
302+
name: denoDist
303+
path: ./denoDist
340304

341-
build-website:
305+
build-website-dist:
342306
name: Build website
343307
runs-on: ubuntu-latest
344308
steps:
@@ -358,3 +322,9 @@ jobs:
358322

359323
- name: Build Docs
360324
run: npm run build:website
325+
326+
- name: Upload denoDist package
327+
uses: actions/upload-artifact@v2
328+
with:
329+
name: websiteDist
330+
path: ./websiteDist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Deploy specified artifact as a branch
2+
on:
3+
workflow_call:
4+
inputs:
5+
workflow_id:
6+
required: true
7+
type: string
8+
artifact_name:
9+
required: true
10+
type: string
11+
target_branch:
12+
required: true
13+
type: string
14+
commit_message:
15+
required: true
16+
type: string
17+
jobs:
18+
deploy-artifact-as-branch:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout `${{ inputs.target_branch }}` branch
22+
uses: actions/checkout@v2
23+
with:
24+
ref: ${{ inputs.target_branch }}
25+
26+
- name: Remove existing files first
27+
run: git rm -r .
28+
29+
- name: Download artifact into cloned branch
30+
run: gh run download "$WORKFLOW_ID" -n "$ARTIFACT_NAME"
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
WORKFLOW_ID: ${{ inputs.workflow_id }}
34+
ARTIFACT_NAME: ${{ inputs.artifact_name }}
35+
36+
- name: Publish target branch
37+
run: |
38+
git add -A
39+
if git diff --staged --quiet; then
40+
echo 'Nothing to publish'
41+
else
42+
git config user.name 'GitHub Action Script'
43+
git config user.email '[email protected]'
44+
45+
git commit -a -m "$COMMIT_MESSAGE"
46+
git push
47+
echo 'Pushed'
48+
fi
49+
env:
50+
TARGET_BRANCH: ${{ inputs.target_branch }}
51+
COMMIT_MESSAGE: ${{ inputs.commit_message }}

0 commit comments

Comments
 (0)