Skip to content

Commit e13a353

Browse files
authored
ci: Add code review pipeline
1 parent 0a59786 commit e13a353

File tree

7 files changed

+198
-12
lines changed

7 files changed

+198
-12
lines changed

.github/actions/setup/action.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Setup
2+
description: Setup Node.js and install dependencies
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Setup Node.js
8+
uses: actions/setup-node@v3
9+
with:
10+
node-version-file: .nvmrc
11+
12+
- name: Cache dependencies
13+
id: yarn-cache
14+
uses: actions/cache@v3
15+
with:
16+
path: |
17+
**/node_modules
18+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }}
19+
restore-keys: |
20+
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
21+
${{ runner.os }}-yarn-
22+
23+
- name: Install dependencies
24+
if: steps.yarn-cache.outputs.cache-hit != 'true'
25+
run: |
26+
yarn install --cwd example --frozen-lockfile
27+
yarn install --frozen-lockfile
28+
shell: bash

.github/workflows/code-review.yaml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: 'Code Review'
2+
on:
3+
push:
4+
branches: ['main', 'master']
5+
pull_request:
6+
types: [opened, synchronize]
7+
workflow_dispatch: {}
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Setup
17+
uses: ./.github/actions/setup
18+
19+
- name: Lint files
20+
run: yarn lint
21+
22+
- name: Typecheck files
23+
run: yarn typecheck
24+
25+
test:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
31+
- name: Setup
32+
uses: ./.github/actions/setup
33+
34+
- name: Run unit tests
35+
run: yarn test --maxWorkers=2 --coverage
36+
37+
build-library:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v3
42+
43+
- name: Setup
44+
uses: ./.github/actions/setup
45+
46+
- name: Build package
47+
run: yarn prepack
48+
49+
build-android:
50+
runs-on: ubuntu-latest
51+
env:
52+
TURBO_CACHE_DIR: .turbo/android
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@v3
56+
57+
- name: Setup
58+
uses: ./.github/actions/setup
59+
60+
- name: Cache turborepo for Android
61+
uses: actions/cache@v3
62+
with:
63+
path: ${{ env.TURBO_CACHE_DIR }}
64+
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
65+
restore-keys: |
66+
${{ runner.os }}-turborepo-android-
67+
68+
- name: Check turborepo cache for Android
69+
run: |
70+
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
71+
72+
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
73+
echo "turbo_cache_hit=1" >> $GITHUB_ENV
74+
fi
75+
76+
- name: Install JDK
77+
if: env.turbo_cache_hit != 1
78+
uses: actions/setup-java@v3
79+
with:
80+
distribution: 'zulu'
81+
java-version: '11'
82+
83+
- name: Finalize Android SDK
84+
if: env.turbo_cache_hit != 1
85+
run: |
86+
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
87+
88+
- name: Cache Gradle
89+
if: env.turbo_cache_hit != 1
90+
uses: actions/cache@v3
91+
with:
92+
path: |
93+
~/.gradle/wrapper
94+
~/.gradle/caches
95+
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
96+
restore-keys: |
97+
${{ runner.os }}-gradle-
98+
99+
- name: Build example for Android
100+
run: |
101+
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
102+
103+
build-ios:
104+
runs-on: macos-latest
105+
env:
106+
TURBO_CACHE_DIR: .turbo/ios
107+
steps:
108+
- name: Checkout
109+
uses: actions/checkout@v3
110+
111+
- name: Setup
112+
uses: ./.github/actions/setup
113+
114+
- name: Cache turborepo for iOS
115+
uses: actions/cache@v3
116+
with:
117+
path: ${{ env.TURBO_CACHE_DIR }}
118+
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('**/yarn.lock') }}
119+
restore-keys: |
120+
${{ runner.os }}-turborepo-ios-
121+
122+
- name: Check turborepo cache for iOS
123+
run: |
124+
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
125+
126+
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
127+
echo "turbo_cache_hit=1" >> $GITHUB_ENV
128+
fi
129+
130+
- name: Cache cocoapods
131+
if: env.turbo_cache_hit != 1
132+
id: cocoapods-cache
133+
uses: actions/cache@v3
134+
with:
135+
path: |
136+
**/ios/Pods
137+
key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
138+
restore-keys: |
139+
${{ runner.os }}-cocoapods-
140+
141+
- name: Install cocoapods
142+
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
143+
run: |
144+
yarn example pods
145+
env:
146+
NO_FLIPPER: 1
147+
148+
- name: Build example for iOS
149+
run: |
150+
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ android/keystores/debug.keystore
6868

6969
# generated by bob
7070
lib/
71+
coverage/

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.18.1
1+
18.16.0

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ SPEC CHECKSUMS:
681681
JOSESwift: 7ff178bb9173ff42c6e990929a9f2fa702a34f69
682682
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
683683
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
684-
pagopa-io-react-native-jwt: a4d0dfb310597d29dde27b07100935a259b13cb0
684+
pagopa-io-react-native-jwt: 9c9f03fbfb87aa5247c51d01e4e5f314bdefc983
685685
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
686686
RCTRequired: c52ee8fb2b35c1b54031dd8e92d88ad4dba8f2ce
687687
RCTTypeSafety: 75fa444becadf0ebfa0a456b8c64560c7c89c7df

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
"ios",
4545
"android"
4646
],
47-
"repository": "https://github.com/pagopa/react-native-jwt",
47+
"repository": "https://github.com/pagopa/io-react-native-jwt",
4848
"author": "PagoPa (https://github.com/pagopa)",
4949
"license": "MIT",
5050
"bugs": {
51-
"url": "https://github.com/pagopa/react-native-jwt/issues"
51+
"url": "https://github.com/pagopa/io-react-native-jwt/issues"
5252
},
53-
"homepage": "https://github.com/pagopa/react-native-jwt#readme",
53+
"homepage": "https://github.com/pagopa/io-react-native-jwt#readme",
5454
"publishConfig": {
55-
"registry": "https://registry.npmjs.org/"
55+
"registry": "https://npm.pkg.github.com"
5656
},
5757
"devDependencies": {
5858
"@commitlint/config-conventional": "^17.0.2",

src/__tests__/jwt_claims_set.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import type { JWSHeaderParameters, JWTPayload } from 'src/types';
22
import verifyJwtClaimSet from './../jwt_claims_set';
33
import { JWTClaimValidationFailed, JWTExpired } from './../utils/errors';
44

5+
const now = new Date();
6+
let addHours = (date: Date, hours: number) => {
7+
date.setHours(date.getHours() + hours);
8+
return date;
9+
};
10+
511
const jwtHeader: JWSHeaderParameters = {
612
typ: 'jwt',
713
kid: 'EC#1',
@@ -11,24 +17,25 @@ const jwtHeader: JWSHeaderParameters = {
1117
const jwtPayload: JWTPayload = {
1218
iss: 'demo',
1319
sub: 'demo',
14-
iat: 1689236635,
15-
exp: 1689240235,
20+
iat: now.getTime() / 1000,
21+
exp: addHours(now, 2).getTime() / 1000,
1622
};
1723

1824
describe('Basic JWT Claims Set verification', function () {
1925
it('must check the parameters correctly', async () => {
2026
const verified = verifyJwtClaimSet(jwtHeader, jwtPayload, {
21-
currentDate: new Date(2023, 6, 13, 10, 30, 0, 0),
2227
typ: 'jwt',
2328
requiredClaims: ['iss', 'sub'],
2429
});
2530
expect(verified).toBe(jwtPayload);
2631
});
2732

2833
it('must fail the check because the JWT has expired', async () => {
29-
expect(() => verifyJwtClaimSet(jwtHeader, jwtPayload)).toThrowError(
30-
JWTExpired
31-
);
34+
expect(() =>
35+
verifyJwtClaimSet(jwtHeader, jwtPayload, {
36+
currentDate: addHours(now, 10),
37+
})
38+
).toThrowError(JWTExpired);
3239
});
3340

3441
it('must fail the check because the typ is wrong', async () => {

0 commit comments

Comments
 (0)