run-apollo-app-example #1468
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: run-apollo-app-example | |
on: | |
workflow_dispatch: # * Treated like a scheduled run | |
inputs: | |
dist-tag: | |
type: string | |
description: NTARH version to test | |
required: true | |
default: 'latest' | |
schedule: | |
- cron: '30 */6 * * *' | |
env: | |
# * Selectively enable debugger verbose output in the pipeline | |
# ? See also: https://www.npmjs.com/package/debug#wildcards | |
# DEBUG: 'next-test-api-route-handler:*' | |
NODE_CURRENT_VERSION: 22.x | |
NODE_OLDER_VERSIONS: '"18.x", "20.x"' | |
jobs: | |
metadata: | |
name: 'gather-metadata' | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
outputs: | |
node-matrix: ${{ steps.set-matrix.outputs.node-matrix }} | |
steps: | |
- name: Report mode statuses | |
run: | | |
if [ -n "$DEBUG" ]; then | |
echo "RUN-APOLLO-APP-EXAMPLE IS RUNNING IN DEBUG MODE ($DEBUG)" | |
else | |
echo '(run-apollo-app-example is not running in debug mode)' | |
fi | |
- name: Gather metadata | |
id: set-matrix | |
run: | | |
echo "node-matrix={\"node\":[$NODE_OLDER_VERSIONS, \"$NODE_CURRENT_VERSION\"]}" >> $GITHUB_OUTPUT | |
! [ -z "$DEBUG" ] && echo "set-output name=node-matrix::{\"node\":[$NODE_OLDER_VERSIONS, \"$NODE_CURRENT_VERSION\"]}" || true | |
check-compat: | |
runs-on: ubuntu-latest | |
needs: metadata | |
timeout-minutes: 10 | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.metadata.outputs.node-matrix) }} | |
steps: | |
# GitHub Actions artifacts cannot handle filenames with certain characters | |
- name: Reify metadata | |
id: reified-metadata | |
env: | |
NODE_VERSION: ${{ matrix.node }} | |
run: > | |
node -p | |
'`node-version-sanitized=${process.env.NODE_VERSION.replaceAll( | |
/[":<>|*?\\\/=,\s'"'"']/g,"-")}`' >> "$GITHUB_OUTPUT" | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
# See: https://github.com/actions/setup-node/issues/214#issuecomment-810829250 | |
- name: Reconfigure git to use HTTP authentication | |
run: > | |
git config --global url."https://github.com/".insteadOf | |
ssh://git@github.com/ | |
- name: Use node ${{ matrix.node }} | |
uses: actions/setup-node@v4.1.0 | |
- name: Cache npm | |
uses: actions/cache@v4 | |
id: cache-npm | |
with: | |
key: | |
npm-node-${{ matrix.node }}-${{ runner.os }}-${{ | |
hashFiles('**/package-lock.json') }} | |
path: ~/.npm | |
restore-keys: npm-node-${{ matrix.node }}-${{ runner.os }}- | |
# Turns out tee eats exit codes... ... sigh | |
# Also, we use npm install over npm ci for more accurate test results | |
- name: Install CI dependencies | |
run: | | |
mkfifo '#pipe.ignore' | |
tee --append /tmp/output.txt < '#pipe.ignore' & | |
npm install --force > '#pipe.ignore' 2>&1 | |
rm '#pipe.ignore' | |
- name: Build externals (we're only interested in util.js) | |
run: npm run build:externals | |
# We need to install Next.js's peer dependencies by hand because it is | |
# possible that Vercel devs publish broken package.json peerDependencies | |
# | |
# Also, note that, when piping stuff, npm install seems to break the pipe | |
# for any processes that come after it. Not sure why, but can be fixed by | |
# rm-ing and re-mkfifo-ing the pipe. | |
- name: Run apollo terminal example | |
# https://bit.ly/38702j0 | |
run: | | |
previous_cwd=$(pwd) | |
mkdir -p /tmp/ntarh-test/test | |
cd /tmp/ntarh-test | |
mkfifo '#pipe.ignore' | |
tee --append /tmp/output.txt < '#pipe.ignore' & | |
extra_installs=$(node -e '(async () => console.log((await require("'"$previous_cwd"'/external-scripts/bin/util.js").getNextjsReactPeerDependencies("next@latest")).join(" ")))()') | |
npm install --force next @apollo/server @as-integrations/next graphql-tag next-test-api-route-handler jest babel-jest @babel/core @babel/preset-env $(echo $extra_installs) > '#pipe.ignore' 2>&1 | |
echo 'module.exports={presets:["@babel/preset-env"]};' > babel.config.js | |
mkdir -p app/api/graphql | |
curl -o app/api/graphql/route.js https://raw.githubusercontent.com/Xunnamius/next-test-api-route-handler/main/apollo_test_raw_app_route | |
curl -o test/integration.test.js https://raw.githubusercontent.com/Xunnamius/next-test-api-route-handler/main/apollo_test_raw_app_test | |
npx jest | |
rm '#pipe.ignore' |