Skip to content

Commit

Permalink
Merge pull request #23 from scratch-auth/github
Browse files Browse the repository at this point in the history
GitHub
  • Loading branch information
toakiryu authored Oct 22, 2024
2 parents 321195b + 931b375 commit 13b52e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
52 changes: 29 additions & 23 deletions .github/workflows/nextjs-package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,65 @@ on:
pull_request:
paths:
- "packages/nextjs/**"
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

services:
scratch-auth:
image: scratch-auth/scratch-auth:latest
ports:
- 4000:4000
options: >-
--env SCRATCH_AUTH_SECRET_KEY=${{ secrets.SCRATCH_AUTH_SECRET_KEY }}
# 環境変数をsecretsに設定しておき、GitHub Actionsから参照します。

env:
SCRATCH_AUTH_SECRET_KEY: ${{ secrets.SCRATCH_AUTH_SECRET_KEY }}
NEXT_PUBLIC_REDIRECT_URL: "http://localhost:3000/api/auth"
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "18"

- name: Install dependencies
working-directory: packages/nextjs
- name: Install dependencies for test package
working-directory: test/nextjs
run: npm install

- name: Run build
- name: NPM Link for test package
working-directory: packages/nextjs
run: npm run build
run: npm link

- name: Set environment variables for Scratch Auth
run: echo "SCRATCH_AUTH_SECRET_KEY=$SCRATCH_AUTH_SECRET_KEY" >> $GITHUB_ENV
- name: Install dependencies & @scratch-auth/nextjs for test package
working-directory: test/nextjs
run: |
npm install && npm link @scratch-auth/nextjs
- name: Install wait-on
run: npm install -g wait-on

- name: Start the Next.js application
working-directory: packages/nextjs
working-directory: test/nextjs
run: npm run dev &

- name: Wait for server to be ready
run: npx wait-on http://localhost:3000

- name: Run authentication test
- name: Wait for server to be ready (using curl)
run: |
curl -X POST http://localhost:3000/api/auth -d "privateCode=test"
echo "Testing authentication successful"
echo "Waiting for the server to be ready..."
for i in {1..10}; do
if curl --silent --fail http://localhost:3000; then
echo "Server is ready!"
break
fi
echo "Waiting for the server... (Attempt $i)"
sleep 5
done
- name: Stop services
run: |
kill $(lsof -t -i:3000)
kill $(lsof -t -i:3000) || true
if: always()

- name: Upload test results
Expand Down
2 changes: 2 additions & 0 deletions packages/nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ Access the app’s homepage at [http://localhost:3000 ↗](http://localhost:3000
up and create the first user.

</Steps>

[@Looky1173](https://github.com/Looky1173) / [@Fun117](https://github.com/Fun117)
6 changes: 3 additions & 3 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"uuid": "^10.0.0"
},
"devDependencies": {
"@types/node": "^22.7.4",
"@types/node": "^22.7.8",
"@types/react": "^18.3.11",
"@types/uuid": "^10.0.0",
"tailwindcss": "^3.4.13",
"typescript": "^5.6.2"
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3"
}
}

0 comments on commit 13b52e0

Please sign in to comment.