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

Fix diff schema on PRs #3071

Merged
merged 5 commits into from
Jan 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions .github/workflows/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,54 @@ on:
workflow_dispatch:
inputs:
base:
description: 'Base ref'
default: 'master'
description: "Base ref"
default: "master"
required: true
head:
description: 'Head ref'
default: 'master'
description: "Head ref"
default: "master"
required: true

jobs:
compute_diff:
runs-on: ubuntu-latest

steps:
# Check out the base commit first and the head commit second. diff-schema
# uses the current commit as the head commit.
- if: github.event_name == 'pull_request'
name: Checkout
name: Checkout PR base commit
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
- if: github.event_name == 'pull_request'
name: Checkout PR merge commit
uses: actions/checkout@v4

- if: github.event_name == 'workflow_dispatch'
name: Checkout
name: Checkout base commit
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.base }}
- if: github.event_name == 'workflow_dispatch'
name: Checkout head commit
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.head }}

- name: 'Setup Go'
- name: "Setup Go"
uses: actions/setup-go@v4
with:
go-version: 1.21.x

- name: 'Setup Terraform'
- name: "Setup Terraform"
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false

- name: 'Install jd'
- name: "Install jd"
run: go install github.com/josephburnett/jd@latest

- run: make diff-schema
env:
BASE_COMMIT: ${{ github.event_name == 'pull_request' && github.base_ref || github.event.inputs.base }}
17 changes: 9 additions & 8 deletions scripts/diff-schema.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#!/usr/bin/env bash
set -eo pipefail

source scripts/libschema.sh

BASE_BRANCH="master"
BASE=${BASE_COMMIT:-"master"}
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

checkout_branch() {
local branch=$1
echo "Checking out branch: $branch"
git checkout $branch
checkout() {
local ref=$1
echo "Checking out ref: $ref"
git checkout $ref
}

if [ -n "$(git status --porcelain)" ]; then
echo "There are uncommitted changes. Please commit them before running this script."
exit 1
fi

CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
NEW_SCHEMA=$(generate_schema)
checkout_branch $BASE_BRANCH
checkout $BASE
CURRENT_SCHEMA=$(generate_schema)
checkout_branch $CURRENT_BRANCH
checkout $CURRENT_BRANCH

set +e
jd -color "$CURRENT_SCHEMA" "$NEW_SCHEMA"
Expand Down
Loading