Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Ruby tests & scripts to Node.js #18

Merged
merged 11 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4
trim_trailing_whitespace = true

[*.json]
indent_size = 2

[*.svg]
max_line_length = off
77 changes: 77 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Publish
on:
push:
branches:
- master
paths:
- 'entries/**'
- 'icons/**'

concurrency:
group: 'publish'
cancel-in-progress: true

jobs:
publish:
name: Build and Publish files
if: github.repository == '2factorauth/passkeys'
permissions:
pages: write
id-token: write
environment: production
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm install --omit=dev

- name: Get modified files
id: diff
run: |
ENTRIES=$(git diff --name-only HEAD^ entries/| tr '\n' ' ')
if [ -n "$ENTRIES" ]; then
echo "entries=${ENTRIES}" >> $GITHUB_OUTPUT
fi

- name: Generate API files
run: node scripts/APIv*.js

- name: Publish changes to Algolia
if: steps.diff.outputs.entries
run: node scripts/Algolia.js ${{ steps.diff.outputs.entries }}
env:
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_INDEX_NAME: ${{ vars.ALGOLIA_INDEX_NAME }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}

- uses: crazy-max/ghaction-import-gpg@v6
id: pgp
with:
gpg_private_key: ${{ secrets.PGP_KEY }}
passphrase: ${{ secrets.PGP_PASSWORD }}

- name: Sign API files
run: bash scripts/Sign.sh
env:
PGP_PASSWORD: ${{ secrets.PGP_PASSWORD }}
PGP_KEY_ID: ${{ steps.pgp.outputs.keyid }}

- name: Prepare publish directory
run: |
rsync -av icons public/

- uses: actions/upload-pages-artifact@v4
with:
path: public/

- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4

- name: Send webhook to Cloudflare
run: curl -X POST -IL "${{ secrets.WEBHOOK }}" -o /dev/null -w '%{http_code}\n' -s
76 changes: 76 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Pull Request tests
on: pull_request
run-name: "${{github.event.pull_request.title}} (#${{ github.event.number }})"
concurrency:
group: ${{ github.event.number }}
cancel-in-progress: true

jobs:
node-tests:
name: JavaScript tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm install --omit=optional

- name: Get modified files
id: diff
run: |
echo "::debug:: Fetching files from ${{ github.api_url }}/repos/${{ github.repository }}/pulls/${{ github.event.number }}/files"
FILES=$(curl -s "${{ github.api_url }}/repos/${{ github.repository }}/pulls/${{ github.event.number }}/files" | jq -r '.[] | select(.status != "removed") | .filename' | tr '\n' ' ')
ENTRIES=$(echo "$FILES" | tr ' ' '\n' | grep -E '^entries/.*\.json$' | tr '\n' ' ')
if [ -n "$ENTRIES" ]; then
echo "entries=${ENTRIES}" >> $GITHUB_OUTPUT
fi
ICONS=$(echo "$FILES" | tr ' ' '\n' | grep -E '^icons/.*$' | tr '\n' ' ')
if [ -n "ICONS" ]; then
echo "ICONS=${ICONS}" >> $GITHUB_OUTPUT
fi

- name: Validate JSON structure
if: steps.diff.outputs.entries
run: node tests/json.js ${{ steps.diff.outputs.entries }}

- name: Validate file extensions and permissions
run: tests/validate-fs.sh

- name: Validate Language codes
if: steps.diff.outputs.entries
run: node tests/languages.js ${{ steps.diff.outputs.entries }}

- name: Validate Region codes
if: steps.diff.outputs.entries
run: node tests/regions.js ${{ steps.diff.outputs.entries }}

- name: Validate Categories
if: steps.diff.outputs.entries
run: node tests/categories.js ${{ steps.diff.outputs.entries }}

- name: Validate Icons
if: ${{ steps.diff.outputs.entries || steps.diff.outputs.icons }}
run: |
node tests/icons.js &
node tests/svg.js ${{ steps.diff.outputs.icons }} &
wait

- name: Validate URL reachability
if: steps.diff.outputs.entries
run: node tests/urls.js ${{ steps.diff.outputs.entries }}
continue-on-error: true

external-tests:
name: External Tests
runs-on: ubuntu-latest
steps:
- name: Call PR Validator
run: |
curl -s --fail-with-body "https://pr-validator.2fa.directory/${{ github.event.repository.name }}/${{ github.event.number }}/" \
-H "Content-Type: application/json"
92 changes: 0 additions & 92 deletions .github/workflows/repository.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ vendor/
# NPM files
node_modules/
package-lock.json
package.json

# OS files
*.DS_Store
Expand Down
16 changes: 0 additions & 16 deletions Gemfile

This file was deleted.

21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "passkeys",
"private": true,
"dependencies": {
"@actions/core": "^1.10.1",
"dotenv": "^16.4.5",
"glob": "^10.4.5"
},
"optionalDependencies": {
"algoliasearch": "^4.24.0",
"jsonschema": "^1.4.1"
},
"devDependencies": {
"@xmldom/xmldom": "^0.8.10",
"abort-controller": "^3.0.0",
"ajv": "^8.17.1",
"ajv-errors": "^3.0.0",
"ajv-formats": "^3.0.1",
"xpath": "^0.0.34"
}
}
Loading