Skip to content

Commit

Permalink
ci: refactor CI to use central flow definition
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Oct 30, 2024
1 parent 97775bc commit 87a638e
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: Compose Workflow

on:
push:
pull_request:
workflow_call:

jobs:
compose:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout source
Expand All @@ -27,13 +24,14 @@ jobs:
- name: Upload Test Subgraph schema
uses: actions/[email protected]
with:
name: test-schema
name: test-compose-schema
path: test-schema.graphql

- name: Compose Supergraph
uses: ./workflows/compose
with:
name: test
routing-url: https://example.com/graphql
subgraph-schema-artifact: test-schema
subgraph-schema-artifact: test-compose-schema
subgraph-schema-filename: test-schema.graphql
supergraph-schema-artifact: compose-supergraph
13 changes: 6 additions & 7 deletions .github/workflows/docs.yaml → .github/workflows/_docs.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Docs CI

on:
push:
pull_request:
workflow_call:
inputs:
publish:
type: boolean
required: true
default: false

jobs:
lint:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout source
Expand All @@ -29,8 +31,6 @@ jobs:
**/*.{md,markdown}
build:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
needs: lint
runs-on: ubuntu-latest
steps:
Expand All @@ -57,7 +57,6 @@ jobs:
path: site

publish_gh_pages:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
permissions:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: Helm Charts
name: Helm Lint

on:
push:
pull_request:
workflow_call:

jobs:
lint:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout source
Expand All @@ -34,3 +31,4 @@ jobs:
lint
--target-branch=${{ github.event.repository.default_branch }}
--validate-maintainers=false
--check-version-increment=false
30 changes: 30 additions & 0 deletions .github/workflows/_supergraph_generate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Generate Supergraph Schema

on:
workflow_call:

jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Install Rover CLI
run: |
curl -sSL https://rover.apollo.dev/nix/latest | sh
echo "$HOME/.rover/bin" >> $GITHUB_PATH
- name: Checkout Source
uses: actions/[email protected]

- name: Compose Supergraph Schema
run: >
rover supergraph compose
--config supergraph-config.yaml
--elv2-license=accept
> supergraph.graphql
- name: Upload New Schema Artifact
uses: actions/[email protected]
with:
name: supergraph.graphql
path: supergraph.graphql

50 changes: 50 additions & 0 deletions .github/workflows/_supergraph_publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Publish Supergraph Schema

on:
workflow_call:
inputs:
publish:
type: boolean
required: true
default: false

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout source
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Setup Helm
uses: azure/[email protected]

- name: Download Schema Artifact
uses: actions/[email protected]
with:
name: supergraph.graphql
path: charts/supergraph

- name: Package Chart
run: |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
helm package charts/supergraph --version $LATEST_TAG
- name: Generate Image Name
run: echo IMAGE_REPOSITORY=oci://ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]') >> $GITHUB_ENV

- name: Log in to GitHub Docker Registry
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Chart
if: ${{ inputs.publish }}
run: helm push $(ls supergraph-*.tgz) ${{ env.IMAGE_REPOSITORY }}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Update Workflow

on:
push:
pull_request:
workflow_call:
secrets:
GRAPH_FEDERATOR:
required: true

jobs:
update:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout source
Expand All @@ -27,16 +27,17 @@ jobs:
- name: Upload Test Subgraph schema
uses: actions/[email protected]
with:
name: test-schema
name: test-update-schema
path: test-schema.graphql

- name: Update Supergraph
uses: ./workflows/update
with:
name: test
routing-url: https://example.com/graphql
subgraph-schema-artifact: test-schema
subgraph-schema-artifact: test-update-schema
subgraph-schema-filename: test-schema.graphql
supergraph-schema-artifact: update-supergraph
github-app-id: 1010045
github-app-private-key: ${{ secrets.GRAPH_FEDERATOR }}
publish: false
51 changes: 51 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
push:
pull_request:

jobs:
helm_lint:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
uses: ./.github/workflows/_helm_lint.yaml

supergraph_generate:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
uses: ./.github/workflows/_supergraph_generate.yaml

supergraph_publish:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
needs:
- helm_lint
- supergraph_generate
uses: ./.github/workflows/_supergraph_publish.yaml
permissions:
contents: read
packages: write
with:
publish: ${{ needs.release_please.outputs.supergraph-chart-released == 'true' }}

compose_workflow:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
uses: ./.github/workflows/_compose_workflow.yaml

update_workflow:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
uses: ./.github/workflows/_update_workflow.yaml
secrets:
GRAPH_FEDERATOR: ${{ secrets.GRAPH_FEDERATOR }}

docs:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
uses: ./.github/workflows/_docs.yaml
permissions:
pages: write
id-token: write
with:
publish: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
121 changes: 0 additions & 121 deletions .github/workflows/schema-compose.yaml

This file was deleted.

Loading

0 comments on commit 87a638e

Please sign in to comment.