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

add CI to compose supergraph schema and publish to OCI #20

Merged
merged 8 commits into from
Jul 2, 2024
Merged
117 changes: 117 additions & 0 deletions .github/workflows/schema-compose.yaml
iamvigneshwars marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Schema

on:
push:
pull_request:

jobs:
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
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/checkout@v4.1.4

- name: Compose Supergraph Schema
run: >
rover supergraph compose
--config supergraph-config.yaml
--elv2-license=accept
> supergraph.graphql

- name: Upload New Schema Artifact
uses: actions/upload-artifact@v4.3.3
with:
name: supergraph.graphql
path: supergraph.graphql

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:
- generate
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout source
uses: actions/checkout@v4.1.4

- name: Setup Helm
uses: azure/setup-helm@v4.0.0

- name: Download Schema Artifact
uses: actions/download-artifact@v4.1.7
with:
name: supergraph.graphql
path: charts/supergraph

- name: Package Chart
run: helm package charts/supergraph

- name: Generate Image Name
run: echo IMAGE_REPOSITORY=oci://ghcr.io/$(echo "${{ github.repository }}-supergraph" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]') >> $GITHUB_ENV

- name: Log in to GitHub Docker Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Chart
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: helm push $(ls supergraph-*.tgz) ${{ env.IMAGE_REPOSITORY }}

compare_schema:
iamvigneshwars marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Install Rover CLI
run: |
curl -sSL https://rover.apollo.dev/nix/latest | sh
echo "$HOME/.rover/bin" >> $GITHUB_PATH

- name: Checkout main branch
uses: actions/checkout@v4.1.4
with:
ref: main

- name: Compose old Supergraph Schema
run: >
rover supergraph compose
--config supergraph-config.yaml
--elv2-license=accept
> /tmp/old_supergraph.graphql

- name: Checkout Source
uses: actions/checkout@v4.1.4

- name: Compose New Supergraph Schema
run: >
rover supergraph compose
--config supergraph-config.yaml
--elv2-license=accept
> supergraph.graphql

- name: Generate Schema Diff
run: |
git --no-pager diff --no-index --no-exit-code --minimal /tmp/old_supergraph.graphql supergraph.graphql > diff.md
if [ -s diff.md ]; then echo "has_diff=true" >> $GITHUB_ENV; fi
sed -i 1,4d diff.md
sed -i '1s/^/```diff\n/; $a```' diff.md
garryod marked this conversation as resolved.
Show resolved Hide resolved

- name: Comment PR with artefact comparison report
if: env.has_diff == 'true'
uses: JoseThen/comment-pr@v1.2.0
with:
file_path: diff.md
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion charts/supergraph/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
apiVersion: v2
name: supergraph
version: 0.1.0
version: 0.1.1
2 changes: 1 addition & 1 deletion charts/supergraph/template/schema-configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: supergraph-schema
name: {{ .Release.Name }}-supergraph-schema
data:
supergraph.graphql: |-
{{ (.Files.Get .Values.supergraphPath) | nindent 4 }}