Skip to content

Commit

Permalink
ci: Extract branch publishing into separate workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Feb 9, 2022
1 parent c8ac989 commit 0d90f0c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 112 deletions.
58 changes: 0 additions & 58 deletions .github/actions/deploy-dir-as-branch/action.yml

This file was deleted.

12 changes: 5 additions & 7 deletions .github/workflows/canary.yaml
Expand Up @@ -7,12 +7,11 @@ on:
- completed
env:
NODE_VERSION_USED_FOR_DEVELOPMENT: 17
CI_WORKFLOW_ID: ${{github.event.workflow_run.id}}
jobs:
publish-canary:
runs-on: ubuntu-latest
name: Publish Canary
if: ${{ github.event.workflow_run.event == 'pull_request' }}
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand All @@ -27,18 +26,17 @@ jobs:
# 'registry-url' is required for 'npm publish'
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
run: npm ci --ignore-scripts

- name: Download event.json
run: gh run download "$CI_WORKFLOW_ID" -n event.json
run: gh run download "$WORKFLOW_ID" -n event.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_ID: ${{github.event.workflow_run.id}}

- name: Download NPM package artifact
run: gh run download "$CI_WORKFLOW_ID" -n npmDist -D npmDist
run: gh run download "$WORKFLOW_ID" -n npmDist -D npmDist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_ID: ${{github.event.workflow_run.id}}

- name: Modify NPM package to be canary release
uses: actions/github-script@v5
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/cd.yml
@@ -0,0 +1,29 @@
name: CD
on:
workflow_run:
workflows:
- CI
types:
- completed
branches:
- main
jobs:
deploy-to-npm-branch:
name: Deploy to `npm` branch
if: github.event.workflow_run.event == 'push'
uses: ./.github/workflows/deploy-artifact-as-branch.yml
with:
workflow_id: ${{github.event.workflow_run.id}}
artifact_name: npmDist
target_branch: npm
commit_message: "Deploy ${{github.event.workflow_run.head_sha}} to 'npm' branch"

deploy-to-deno-branch:
name: Deploy to `deno` branch
if: github.event.workflow_run.event == 'push'
uses: ./.github/workflows/deploy-artifact-as-branch.yml
with:
workflow_id: ${{github.event.workflow_run.id}}
artifact_name: denoDist
target_branch: deno
commit_message: "Deploy ${{github.event.workflow_run.head_sha}} to 'deno' branch"
64 changes: 17 additions & 47 deletions .github/workflows/ci.yml
Expand Up @@ -246,8 +246,8 @@ jobs:
path: ./npm-dist-diff.html
if-no-files-found: ignore

build-npm-package:
name: Build artifact with NPM package
build-npm-dist:
name: Build 'npmDist' artifact
runs-on: ubuntu-latest
needs: [test, fuzz, lint, integrationTests]
steps:
Expand All @@ -268,52 +268,16 @@ jobs:
- name: Build NPM package
run: npm run build:npm

- name: Upload NPM package
- name: Upload npmDist package
uses: actions/upload-artifact@v2
with:
name: npmDist
path: ./npmDist

deploy-to-npm-branch:
name: Deploy to `npm` branch
build-deno-dist:
name: Build 'denoDist' artifact
runs-on: ubuntu-latest
if: |
github.event_name == 'push' &&
github.repository == 'graphql/graphql-js' &&
github.ref == 'refs/heads/main'
needs: [test, fuzz, lint, checkForCommonlyIgnoredFiles, integrationTests]
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@v2
with:
cache: npm
node-version: ${{ env.NODE_VERSION_USED_FOR_DEVELOPMENT }}

- name: Install Dependencies
run: npm ci --ignore-scripts

- name: Build NPM package
run: npm run build:npm

- name: Deploy to `npm` branch
uses: ./.github/actions/deploy-dir-as-branch
with:
src_dir: npmDist
target_branch: npm

deploy-to-deno-branch:
name: Deploy to `deno` branch
runs-on: ubuntu-latest
if: |
github.event_name == 'push' &&
github.repository == 'graphql/graphql-js' &&
github.ref == 'refs/heads/main'
needs: [test, fuzz, lint, checkForCommonlyIgnoredFiles, integrationTests]
needs: [test, fuzz, lint, integrationTests]
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand All @@ -332,13 +296,13 @@ jobs:
- name: Build Deno package
run: npm run build:deno

- name: Deploy to `deno` branch
uses: ./.github/actions/deploy-dir-as-branch
- name: Upload denoDist package
uses: actions/upload-artifact@v2
with:
src_dir: denoDist
target_branch: deno
name: denoDist
path: ./denoDist

build-website:
build-website-dist:
name: Build website
runs-on: ubuntu-latest
steps:
Expand All @@ -358,3 +322,9 @@ jobs:

- name: Build Docs
run: npm run build:website

- name: Upload denoDist package
uses: actions/upload-artifact@v2
with:
name: websiteDist
path: ./websiteDist
51 changes: 51 additions & 0 deletions .github/workflows/deploy-artifact-as-branch.yml
@@ -0,0 +1,51 @@
name: Deploy specified artifact as a branch
on:
workflow_call:
inputs:
workflow_id:
required: true
type: string
artifact_name:
required: true
type: string
target_branch:
required: true
type: string
commit_message:
required: true
type: string
jobs:
deploy-artifact-as-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout `${{ inputs.target_branch }}` branch
uses: actions/checkout@v2
with:
ref: ${{ inputs.target_branch }}

- name: Remove existing files first
run: git rm -r .

- name: Download artifact into cloned branch
run: gh run download "$WORKFLOW_ID" -n "$ARTIFACT_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_ID: ${{ inputs.workflow_id }}
ARTIFACT_NAME: ${{ inputs.artifact_name }}

- name: Publish target branch
run: |
git add -A
if git diff --staged --quiet; then
echo 'Nothing to publish'
else
git config user.name 'GitHub Action Script'
git config user.email 'please@open.issue'
git commit -a -m "$COMMIT_MESSAGE"
git push
echo 'Pushed'
fi
env:
TARGET_BRANCH: ${{ inputs.target_branch }}
COMMIT_MESSAGE: ${{ inputs.commit_message }}

0 comments on commit 0d90f0c

Please sign in to comment.