Skip to content

Commit 8a21be4

Browse files
committed
feat: Add configuration and CI/CD setup
1 parent 03fdc29 commit 8a21be4

File tree

8 files changed

+254
-6
lines changed

8 files changed

+254
-6
lines changed

.woodpecker/buildRelease.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
#!/bin/bash
3+
4+
# write npm run output both to console and to build.log
5+
npm run build 2>&1 | tee build.log
6+
build_status=${PIPESTATUS[0]}
7+
8+
# if exist status from the npm run build is not 0
9+
# then exit with the status code from the npm run build
10+
if [ $build_status -ne 0 ]; then
11+
echo "Build failed. Exiting with status code $build_status"
12+
exit $build_status
13+
fi

.woodpecker/buildSlackNotify.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
set -x
4+
5+
COMMIT_SHORT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
6+
7+
8+
if [ "$CI_STEP_STATUS" = "success" ]; then
9+
MESSAGE="Did a build without issues on \`$CI_REPO_NAME/$CI_COMMIT_BRANCH\`. Commit: _${CI_COMMIT_MESSAGE}_ (<$CI_COMMIT_URL|$COMMIT_SHORT_SHA>)"
10+
11+
curl -s -X POST -H "Content-Type: application/json" -d '{
12+
"username": "'"$CI_COMMIT_AUTHOR"'",
13+
"icon_url": "'"$CI_COMMIT_AUTHOR_AVATAR"'",
14+
"attachments": [
15+
{
16+
"mrkdwn_in": ["text", "pretext"],
17+
"color": "#36a64f",
18+
"text": "'"$MESSAGE"'"
19+
}
20+
]
21+
}' "$DEVELOPERS_SLACK_WEBHOOK"
22+
exit 0
23+
fi
24+
export BUILD_LOG=$(cat ./build.log)
25+
26+
BUILD_LOG=$(echo $BUILD_LOG | sed 's/"/\\"/g')
27+
28+
MESSAGE="Broke \`$CI_REPO_NAME/$CI_COMMIT_BRANCH\` with commit _${CI_COMMIT_MESSAGE}_ (<$CI_COMMIT_URL|$COMMIT_SHORT_SHA>)"
29+
CODE_BLOCK="\`\`\`$BUILD_LOG\n\`\`\`"
30+
31+
echo "Sending slack message to developers $MESSAGE"
32+
# Send the message
33+
curl -sS -X POST -H "Content-Type: application/json" -d '{
34+
"username": "'"$CI_COMMIT_AUTHOR"'",
35+
"icon_url": "'"$CI_COMMIT_AUTHOR_AVATAR"'",
36+
"attachments": [
37+
{
38+
"mrkdwn_in": ["text", "pretext"],
39+
"color": "#8A1C12",
40+
"text": "'"$CODE_BLOCK"'",
41+
"pretext": "'"$MESSAGE"'"
42+
}
43+
]
44+
}' "$DEVELOPERS_SLACK_WEBHOOK" 2>&1

.woodpecker/release.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
clone:
2+
git:
3+
image: woodpeckerci/plugin-git
4+
settings:
5+
partial: false
6+
depth: 5
7+
8+
steps:
9+
init-secrets:
10+
when:
11+
- event: push
12+
image: infisical/cli
13+
environment:
14+
INFISICAL_TOKEN:
15+
from_secret: VAULT_TOKEN
16+
commands:
17+
- infisical export --domain https://vault.devforth.io/api --format=dotenv-export --env="prod" > /woodpecker/deploy.vault.env
18+
secrets:
19+
- VAULT_TOKEN
20+
21+
release:
22+
image: node:20
23+
when:
24+
- event: push
25+
commands:
26+
- apt update && apt install -y rsync
27+
- export $(cat /woodpecker/deploy.vault.env | xargs)
28+
- npm clean-install
29+
- /bin/bash ./.woodpecker/buildRelease.sh
30+
- npm audit signatures
31+
- npx semantic-release
32+
33+
slack-on-failure:
34+
when:
35+
- event: push
36+
status: [failure, success]
37+
- event: push
38+
image: curlimages/curl
39+
commands:
40+
- export $(cat /woodpecker/deploy.vault.env | xargs)
41+
- /bin/sh ./.woodpecker/buildSlackNotify.sh
42+

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
# Changelog
3+
4+
The complete changelog is available on the [GitHub Releases page](https://github.com/devforth/adminforth-sso-auth/releases).
5+

custom/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".", // This should point to your project root
4+
"paths": {
5+
"@/*": [
6+
// "node_modules/adminforth/dist/spa/src/*"
7+
"../../../spa/src/*"
8+
],
9+
"*": [
10+
// "node_modules/adminforth/dist/spa/node_modules/*"
11+
"../../../spa/node_modules/*"
12+
],
13+
"@@/*": [
14+
// "node_modules/adminforth/dist/spa/src/*"
15+
"."
16+
]
17+
}
18+
}
19+
}

package.json

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
11
{
2-
"name": "adminforth-sso-auth",
2+
"name": "@adminforth/sso-auth",
33
"version": "1.0.0",
4-
"main": "index.ts",
4+
"main": "dist/index.js",
5+
"types": "dist/index.d.ts",
56
"scripts": {
6-
"prepare": "npm link adminforth"
7+
"rollout": "tsc && rsync -av --exclude 'node_modules' custom dist/",
8+
"prepare": "npm link adminforth"
79
},
8-
"author": "",
9-
"license": "ISC",
10-
"description": ""
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/devforth/adminforth-sso-auth"
13+
},
14+
"keywords": ["adminforth", "sso", "auth", "oauth", "google auth", "github auth"],
15+
"author": "devforth",
16+
"license": "MIT",
17+
"description": "AdminForth SSO Auth Plugin",
18+
"devDependencies": {
19+
"@types/node": "^22.10.7",
20+
"semantic-release": "^24.2.1",
21+
"semantic-release-slack-bot": "^4.0.2",
22+
"typescript": "^5.7.3"
23+
},
24+
"release": {
25+
"plugins": [
26+
"@semantic-release/commit-analyzer",
27+
"@semantic-release/release-notes-generator",
28+
"@semantic-release/npm",
29+
"@semantic-release/github",
30+
[
31+
"semantic-release-slack-bot",
32+
{
33+
"notifyOnSuccess": true,
34+
"notifyOnFail": true,
35+
"slackIcon": ":package:",
36+
"markdownReleaseNotes": true
37+
}
38+
]
39+
],
40+
"branches": [
41+
"main",
42+
{
43+
"name": "next",
44+
"prerelease": true
45+
}
46+
]
47+
}
1148
}

tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include*/
4+
"module": "node16", /* Specify what module code is generated. */
5+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
6+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. */
7+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
8+
"strict": false, /* Enable all strict type-checking options. */
9+
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
10+
},
11+
"exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
12+
}

types.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { AdminForthResource, IAdminForth, IHttpServer } from 'adminforth';
2+
3+
/**
4+
* Configuration for an OAuth2 provider adapter
5+
*/
6+
export interface OAuth2ProviderAdapter {
7+
/**
8+
* Unique identifier for this OAuth provider
9+
*/
10+
providerId: string;
11+
12+
/**
13+
* Display name of the provider shown in the UI
14+
*/
15+
providerName: string;
16+
17+
/**
18+
* URL to provider's logo image to show in login button
19+
*/
20+
providerLogo?: string;
21+
22+
/**
23+
* Validate adapter configuration
24+
* Throws error if configuration is invalid
25+
*/
26+
validate(): void;
27+
28+
/**
29+
* Get OAuth2 authorization URL that user will be redirected to
30+
*/
31+
getAuthorizationUrl(): string;
32+
33+
/**
34+
* Exchange authorization code for access token and user info
35+
*/
36+
exchangeCodeForToken(code: string): Promise<{
37+
error?: string;
38+
userInfo?: {
39+
email: string;
40+
name?: string;
41+
picture?: string;
42+
[key: string]: any;
43+
};
44+
}>;
45+
}
46+
47+
/**
48+
* Plugin options for SSO authentication
49+
*/
50+
export interface PluginOptions {
51+
/**
52+
* OAuth2 provider adapter implementation
53+
*/
54+
provider: OAuth2ProviderAdapter;
55+
56+
/**
57+
* Optional callback URL override
58+
* If not provided, will use default AdminForth callback URL
59+
*/
60+
callbackUrl?: string;
61+
62+
/**
63+
* Optional function to transform user info from provider
64+
* into AdminForth user record before saving
65+
*/
66+
transformUserInfo?: (userInfo: any) => Promise<Record<string, any>>;
67+
68+
/**
69+
* Optional function to validate if user is allowed to login
70+
* For example to check if email domain is allowed
71+
*/
72+
validateUser?: (userInfo: any) => Promise<{
73+
allowed: boolean;
74+
error?: string;
75+
}>;
76+
}

0 commit comments

Comments
 (0)