Skip to content

CI and deploy steps for docs #58

CI and deploy steps for docs

CI and deploy steps for docs #58

Workflow file for this run

name: Build & Deploy spec to Netlify
on:
pull_request:
branches:
- main
push:
branches:
# testing only, not allowed to run on OpenLineage/OpenLineage repo
- test-docs-deploy
jobs:
generate_spec:
if: |
(github.ref == 'refs/heads/test-docs-deploy' && github.repository != 'OpenLineage/OpenLineage' ) ||
(github.event.pull_request.merged == true && github.repository == 'OpenLineage/OpenLineage')
name: 'Commit Spec definition'
runs-on: ubuntu-latest
env:
branch: ${{ github.head_ref || github.ref_name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: shogo82148/actions-setup-perl@v1
with:
perl-version: "5.38"
- name: Check changes
id: check-changes
run: |
if git diff --name-only --exit-code HEAD^ HEAD -- 'spec/*.json' 'spec/OpenLineage.yml' >> /dev/null; then
echo "no changes in spec detected, skipping publishing spec"
exit 1
fi
echo "spec changes detected"
exit 0
continue-on-error: true
- name: Check spec changes
if: steps.check-changes.outcome == 'success'
run: |
# Copy changed spec JSON files to target location
git diff --name-only HEAD^ HEAD -- 'spec/*.json' | while read LINE; do
# ignore registry files
if [[ $LINE =~ "registry.json" ]]; then
continue
fi
# extract target file name from $id field in spec files
URL=$(cat $LINE | jq -r '.["$id"]')
# extract target location in website repo
LOC="website/static/${URL#*//*/}"
LOC_DIR="${LOC%/*}"
# create dir if necessary, and copy files
echo "change detected in $LINE"
mkdir -p $LOC_DIR
cp $LINE $LOC
done
- name: Generate openapi
if: steps.check-changes.outcome == 'success'
run: |
SPEC_DIR="$(pwd)/website/static/spec"
APIDOC_DIR="$(pwd)/website/static/apidocs"
pushd $SPEC_DIR
LATEST_VERSION=$(find . -maxdepth 1 | grep -v 'facets' | grep '[0-9]*-[0-9]-[0-9]' | sort -Vr | head -1)
echo latest version is $LATEST_VERSION
rm -f ./OpenLineage.json 2>/dev/null
perl -i -pe"s/version: [[:alnum:]\.-]*/version: ${LATEST_VERSION:2}/g" ./OpenLineage.yml
echo Versions updated
mkdir "${LATEST_VERSION}/facets"
for i in $(ls -d ./facets/* | sort); do cp $i/*.json ${LATEST_VERSION}/facets; done;
echo "LATEST_VERSION=${LATEST_VERSION}" >> "$GITHUB_ENV"
pushd $LATEST_VERSION
ln -sf ../OpenLineage.yml .
popd
- name: Generate redoc
if: steps.check-changes.outcome == 'success'
uses: seeebiii/redoc-cli-github-action@v10
with:
args: 'build --output "${APIDOC_DIR}/openapi/index.html" "${SPEC_DIR}/${LATEST_VERSION}/OpenLineage.yml" --title "OpenLineage API Docs"'
- name: Clean temp files
pushd $LATEST_VERSION
rm -rf facets
rm OpenLineage.yml
popd
- name: Commit changes
if: steps.check-changes.outcome == 'success'
run: |
# verify if there are any changes
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
git config user.name github-actions
git config user.email [email protected]
git fetch
git checkout ${{ env.branch }}
git add website/static/*
git commit -m "[generated] adding spec changes"
git push
else
echo "nothing to commit"
fi
netlify-deploy-changes:
uses: ./.github/workflows/netlify-deploy.yml
needs: generate_spec
with:
branch: ${{ github.head_ref || github.ref_name }} # shall be `main` or `test-docs-deploy` for testing
secrets:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_TOKEN_SECRET: ${{ secrets.NETLIFY_TOKEN_SECRET }}