Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Extract branch publishing into separate workflow #3488

Merged
merged 1 commit into from Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 }}