diff --git a/.github/workflows/update-public-api-reference.yml b/.github/workflows/update-public-api-reference.yml new file mode 100644 index 0000000..262b8c8 --- /dev/null +++ b/.github/workflows/update-public-api-reference.yml @@ -0,0 +1,80 @@ +# update-api-reference.yml +name: Update Public API Reference + +on: + schedule: + # Run at midnight every Saturday + - cron: '0 0 * * 6' + workflow_dispatch: # Manual trigger + pull_request: + branches: [ main ] # Specify the branches for which the action should run on PR + +jobs: + update-api-reference: + runs-on: ubuntu-latest + + steps: + - name: Checkout GaloyMoney/galoy repo + uses: actions/checkout@v3 + with: + repository: 'GaloyMoney/galoy' + path: 'galoy' + fetch-depth: 0 + + - name: Get current commit hash + run: echo "CURRENT_COMMIT_HASH=$(git -C galoy rev-parse HEAD)" >> $GITHUB_ENV + + - name: Hash current schema.graphql + run: | + echo "CURRENT_HASH=$(sha256sum galoy/core/api/src/graphql/public/schema.graphql | awk '{ print $1 }')" >> $GITHUB_ENV + + - name: Checkout GaloyMoney/galoy to a week ago + run: | + week_old_commit=$(git -C galoy rev-list -n 1 --before='1 week ago' main) + echo "Check out to the commit: $week_old_commit" + git -C galoy checkout $week_old_commit + + - name: Hash the week old schema.graphql + run: echo "WEEK_OLD_HASH=$(sha256sum galoy/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 reference in the last week." + + - name: Checkout dev.galoy.io repo + if: env.CURRENT_HASH != env.WEEK_OLD_HASH + uses: actions/checkout@v3 + with: + repository: 'GaloyMoney/dev.galoy.io' + path: 'dev.galoy.io' + ref: 'main' + fetch-depth: 0 + + - name: Build and update the API reference + if: env.CURRENT_HASH != env.WEEK_OLD_HASH + run: | + # checkout galoy + cd galoy + git checkout ${{ env.CURRENT_COMMIT_HASH }} + + cd ../dev.galoy.io + + # deps + yarn add spectaql --non-interactive + + # build public api reference + npx spectaql scripts/spectaql/spectaql-config-public-api.yml \ + -t static -f public-api-reference.html + + # set dark mode + sed -i 's/spectaql.min.css/spectaql.dark.css/' static/public-api-reference.html + + # Commit and push changes + git config --local user.name 'github-actions[bot]' + git config --local user.email 'github-actions[bot]@users.noreply.github.com' + git add . + git commit -m "docs: public api reference update to ${{ env.CURRENT_COMMIT_HASH }}" + git log + #git push origin main + diff --git a/Makefile b/Makefile index afb6f0e..b700dc1 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,5 @@ start-local-dev: yarn start generate-api-reference: - scripts/generate-galoy-api-reference.sh + scripts/generate-public-api-reference.sh + scripts/generate-admin-api-reference.sh diff --git a/scripts/generate-admin-api-reference.sh b/scripts/generate-admin-api-reference.sh new file mode 100755 index 0000000..2a2ca9b --- /dev/null +++ b/scripts/generate-admin-api-reference.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# deps +if ! git --version; then sudo apt-get install -y git; fi +if ! node --version; then sudo apt-get install -y nodejs; fi +if ! yarn --version; then sudo apt-get install -y yarn; fi +if ! npx spectaql --version; then yarn add spectaql --non-interactive; fi + +mkdir -p .temp +cd .temp || exit 1 + +# checkout galoy +if [ ! -d "galoy" ]; then + git clone https://github.com/GaloyMoney/galoy +fi +cd galoy || exit 1 + +# build admin api reference +npx spectaql ./../../scripts/spectaql/spectaql-config-admin-api.yml \ + -t ./../../static -f admin-api-reference.html || exit 1 + +# set dark mode +sed -i 's/spectaql.min.css/spectaql.dark.css/' ./../../static/admin-api-reference.html diff --git a/scripts/generate-galoy-api-reference.sh b/scripts/generate-public-api-reference.sh similarity index 73% rename from scripts/generate-galoy-api-reference.sh rename to scripts/generate-public-api-reference.sh index cfeb562..2d5d155 100755 --- a/scripts/generate-galoy-api-reference.sh +++ b/scripts/generate-public-api-reference.sh @@ -19,10 +19,5 @@ cd galoy || exit 1 npx spectaql ./../../scripts/spectaql/spectaql-config-public-api.yml \ -t ./../../static -f public-api-reference.html || exit 1 -# build admin api reference -npx spectaql ./../../scripts/spectaql/spectaql-config-admin-api.yml \ - -t ./../../static -f admin-api-reference.html || exit 1 - # set dark mode sed -i 's/spectaql.min.css/spectaql.dark.css/' ./../../static/public-api-reference.html -sed -i 's/spectaql.min.css/spectaql.dark.css/' ./../../static/admin-api-reference.html