Skip to content

Update Public API Reference #20

Update Public API Reference

Update Public API Reference #20

# update-public-api-reference.yml
name: Update Public API Reference
on:
schedule:
# Run at six every Monday
- cron: '0 6 * * 1'
workflow_dispatch: # Manual trigger
jobs:
update-public-api-reference:
runs-on: ubuntu-latest
steps:
- uses: DeterminateSystems/nix-installer-action@v12
- uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Checkout GaloyMoney/blink repo
uses: actions/checkout@v3
with:
repository: 'GaloyMoney/blink'
path: 'blink'
fetch-depth: 0
- name: Get current commit hash
run: echo "CURRENT_COMMIT_HASH=$(git -C blink rev-parse HEAD)" >> $GITHUB_ENV
- name: Hash current schema.graphql
run: |
echo "CURRENT_HASH=$(sha256sum blink/core/api/src/graphql/public/schema.graphql | awk '{ print $1 }')" >> $GITHUB_ENV
- name: Checkout GaloyMoney/blink to a week ago
run: |
week_old_commit=$(git -C blink rev-list -n 1 --before='1 week ago' main)
echo "Check out to the commit: $week_old_commit"
git -C blink checkout $week_old_commit
- name: Hash the week old schema.graphql
run: echo "WEEK_OLD_HASH=$(sha256sum blink/core/api/src/graphql/public/schema.graphql | awk '{ print $1 }')" >> $GITHUB_ENV
- name: Check if hashes are the same
if: env.CURRENT_HASH == env.WEEK_OLD_HASH
run: |
echo "There were no changes to the public API schema during the last week."
- name: Checkout dev.blink.sv repo
if: env.CURRENT_HASH != env.WEEK_OLD_HASH
uses: actions/checkout@v3
with:
repository: 'GaloyMoney/dev.blink.sv'
path: 'dev.blink.sv'
ref: 'main'
fetch-depth: 0
- name: Build and update the API reference
if: env.CURRENT_HASH != env.WEEK_OLD_HASH
run: |
# deps
nix-shell -p yarn --run "yarn add spectaql --non-interactive"
# checkout blink
cd blink
git checkout ${{ env.CURRENT_COMMIT_HASH }}
# build public api reference
nix-shell -p yarn --run "npx spectaql ../dev.blink.sv/scripts/spectaql/spectaql-config-public-api.yml \
-t ../dev.blink.sv/static -f public-api-reference.html"
# set dark mode
sed -i 's/spectaql.min.css/spectaql.dark.css/' ../dev.blink.sv/static/public-api-reference.html
# commit and push changes
cd ../dev.blink.sv
git config --local user.name 'github-actions[bot]'
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
git add .
short_commit_hash=$(echo ${{ env.CURRENT_COMMIT_HASH }} | cut -c1-7)
git commit -m "docs: public api reference update to blink commit $short_commit_hash"
git push origin main
# Install Dependencies
nix-shell -p yarn --run "yarn install --frozen-lockfile"
# Build
nix-shell -p yarn --run "yarn build"
- name: Check if build directory exists
if: env.CURRENT_HASH != env.WEEK_OLD_HASH
run: |
if [ -d "./dev.blink.sv/build" ]; then
echo "DIR_EXISTS=true" >> $GITHUB_ENV
else
echo "DIR_EXISTS=false" >> $GITHUB_ENV
fi
- name: Deploy to GitHub Pages
if: env.CURRENT_HASH != env.WEEK_OLD_HASH && env.DIR_EXISTS == 'true'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dev.blink.sv/build
user_name: github-actions[bot]
user_email: 41898282+github-actions[bot]@users.noreply.github.com