Skip to content

Commit 061e43c

Browse files
authored
Rewrite Ruby tests & scripts to Node.js (#18)
* initial test rewriting * Add category test * Add signing script * Rewrite more scripts to Node.js * Clean up scripts * Reword warning * Clean up code * Rename image test to icons test * Add URL reachability test * Add missing dependencies
1 parent 78b6696 commit 061e43c

31 files changed

+851
-693
lines changed

.editorconfig

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ root = true
33
[*]
44
charset = utf-8
55
end_of_line = lf
6-
indent_size = 4
6+
indent_size = 2
77
indent_style = space
88
insert_final_newline = true
99
max_line_length = 120
1010
tab_width = 4
1111
trim_trailing_whitespace = true
1212

13-
[*.json]
14-
indent_size = 2
15-
1613
[*.svg]
1714
max_line_length = off

.github/workflows/publish.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths:
7+
- 'entries/**'
8+
- 'icons/**'
9+
10+
concurrency:
11+
group: 'publish'
12+
cancel-in-progress: true
13+
14+
jobs:
15+
publish:
16+
name: Build and Publish files
17+
if: github.repository == '2factorauth/passkeys'
18+
permissions:
19+
pages: write
20+
id-token: write
21+
environment: production
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '20'
30+
31+
- name: Install dependencies
32+
run: npm install --omit=dev
33+
34+
- name: Get modified files
35+
id: diff
36+
run: |
37+
ENTRIES=$(git diff --name-only HEAD^ entries/| tr '\n' ' ')
38+
if [ -n "$ENTRIES" ]; then
39+
echo "entries=${ENTRIES}" >> $GITHUB_OUTPUT
40+
fi
41+
42+
- name: Generate API files
43+
run: node scripts/APIv*.js
44+
45+
- name: Publish changes to Algolia
46+
if: steps.diff.outputs.entries
47+
run: node scripts/Algolia.js ${{ steps.diff.outputs.entries }}
48+
env:
49+
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
50+
ALGOLIA_INDEX_NAME: ${{ vars.ALGOLIA_INDEX_NAME }}
51+
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
52+
53+
- uses: crazy-max/ghaction-import-gpg@v6
54+
id: pgp
55+
with:
56+
gpg_private_key: ${{ secrets.PGP_KEY }}
57+
passphrase: ${{ secrets.PGP_PASSWORD }}
58+
59+
- name: Sign API files
60+
run: bash scripts/Sign.sh
61+
env:
62+
PGP_PASSWORD: ${{ secrets.PGP_PASSWORD }}
63+
PGP_KEY_ID: ${{ steps.pgp.outputs.keyid }}
64+
65+
- name: Prepare publish directory
66+
run: |
67+
rsync -av icons public/
68+
69+
- uses: actions/upload-pages-artifact@v4
70+
with:
71+
path: public/
72+
73+
- name: Deploy to GitHub Pages
74+
uses: actions/deploy-pages@v4
75+
76+
- name: Send webhook to Cloudflare
77+
run: curl -X POST -IL "${{ secrets.WEBHOOK }}" -o /dev/null -w '%{http_code}\n' -s

.github/workflows/pull_request.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Pull Request tests
2+
on: pull_request
3+
run-name: "${{github.event.pull_request.title}} (#${{ github.event.number }})"
4+
concurrency:
5+
group: ${{ github.event.number }}
6+
cancel-in-progress: true
7+
8+
jobs:
9+
node-tests:
10+
name: JavaScript tests
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
21+
- name: Install dependencies
22+
run: npm install --omit=optional
23+
24+
- name: Get modified files
25+
id: diff
26+
run: |
27+
echo "::debug:: Fetching files from ${{ github.api_url }}/repos/${{ github.repository }}/pulls/${{ github.event.number }}/files"
28+
FILES=$(curl -s "${{ github.api_url }}/repos/${{ github.repository }}/pulls/${{ github.event.number }}/files" | jq -r '.[] | select(.status != "removed") | .filename' | tr '\n' ' ')
29+
ENTRIES=$(echo "$FILES" | tr ' ' '\n' | grep -E '^entries/.*\.json$' | tr '\n' ' ')
30+
if [ -n "$ENTRIES" ]; then
31+
echo "entries=${ENTRIES}" >> $GITHUB_OUTPUT
32+
fi
33+
ICONS=$(echo "$FILES" | tr ' ' '\n' | grep -E '^icons/.*$' | tr '\n' ' ')
34+
if [ -n "ICONS" ]; then
35+
echo "ICONS=${ICONS}" >> $GITHUB_OUTPUT
36+
fi
37+
38+
- name: Validate JSON structure
39+
if: steps.diff.outputs.entries
40+
run: node tests/json.js ${{ steps.diff.outputs.entries }}
41+
42+
- name: Validate file extensions and permissions
43+
run: tests/validate-fs.sh
44+
45+
- name: Validate Language codes
46+
if: steps.diff.outputs.entries
47+
run: node tests/languages.js ${{ steps.diff.outputs.entries }}
48+
49+
- name: Validate Region codes
50+
if: steps.diff.outputs.entries
51+
run: node tests/regions.js ${{ steps.diff.outputs.entries }}
52+
53+
- name: Validate Categories
54+
if: steps.diff.outputs.entries
55+
run: node tests/categories.js ${{ steps.diff.outputs.entries }}
56+
57+
- name: Validate Icons
58+
if: ${{ steps.diff.outputs.entries || steps.diff.outputs.icons }}
59+
run: |
60+
node tests/icons.js &
61+
node tests/svg.js ${{ steps.diff.outputs.icons }} &
62+
wait
63+
64+
- name: Validate URL reachability
65+
if: steps.diff.outputs.entries
66+
run: node tests/urls.js ${{ steps.diff.outputs.entries }}
67+
continue-on-error: true
68+
69+
external-tests:
70+
name: External Tests
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Call PR Validator
74+
run: |
75+
curl -s --fail-with-body "https://pr-validator.2fa.directory/${{ github.event.repository.name }}/${{ github.event.number }}/" \
76+
-H "Content-Type: application/json"

.github/workflows/repository.yml

-92
This file was deleted.

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ vendor/
1313
# NPM files
1414
node_modules/
1515
package-lock.json
16-
package.json
1716

1817
# OS files
1918
*.DS_Store

Gemfile

-16
This file was deleted.

package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "passkeys",
3+
"private": true,
4+
"dependencies": {
5+
"@actions/core": "^1.10.1",
6+
"dotenv": "^16.4.5",
7+
"glob": "^10.4.5"
8+
},
9+
"optionalDependencies": {
10+
"algoliasearch": "^4.24.0",
11+
"jsonschema": "^1.4.1"
12+
},
13+
"devDependencies": {
14+
"@xmldom/xmldom": "^0.8.10",
15+
"abort-controller": "^3.0.0",
16+
"ajv": "^8.17.1",
17+
"ajv-errors": "^3.0.0",
18+
"ajv-formats": "^3.0.1",
19+
"xpath": "^0.0.34"
20+
}
21+
}

0 commit comments

Comments
 (0)