Skip to content
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
46 changes: 46 additions & 0 deletions .github/workflows/deploy-context-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy context (Dev)

on:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: deploy-context-dev
cancel-in-progress: false

jobs:
build-and-deploy:
name: Build and deploy /context to CloudFront (Dev)
runs-on: ubuntu-latest
env:
S3_BUCKET: ${{ secrets.S3_BUCKET_CONTEXT_DEV }}
CF_DISTRIBUTION: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID_DEV }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build context files
run: bash scripts/copy-files.sh

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
aws-region: ap-southeast-1

- name: Sync context JSON to S3
run: |
aws s3 sync ./public/context "s3://${S3_BUCKET}/context/" \
--delete \
--content-type "application/json" \
--cache-control "public, max-age=31536000, immutable"

- name: Invalidate CloudFront /context/*
run: |
aws cloudfront create-invalidation \
--distribution-id "${CF_DISTRIBUTION}" \
--paths "/context/*"
48 changes: 48 additions & 0 deletions .github/workflows/deploy-context-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deploy context (Production)

on:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: deploy-context-prod
cancel-in-progress: false

jobs:
build-and-deploy:
name: Build and deploy /context to CloudFront (Production)
runs-on: ubuntu-latest
env:
S3_BUCKET: ${{ secrets.S3_BUCKET_CONTEXT_PROD }}
CF_DISTRIBUTION: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID_PROD }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main

- name: Build context files
run: bash scripts/copy-files.sh

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-1

- name: Sync context JSON to S3
run: |
aws s3 sync ./public/context "s3://${S3_BUCKET}/context/" \
--delete \
--content-type "application/json" \
--cache-control "public, max-age=31536000, immutable"

- name: Invalidate CloudFront /context/*
run: |
aws cloudfront create-invalidation \
--distribution-id "${CF_DISTRIBUTION}" \
--paths "/context/*"
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"lint": "nx run-many --target=lint",
"lint:fix": "nx run-many --target=lint --fix",
"build": "nx run-many --target=build",
"copy-files": "bash ./scripts/copy-files.sh",
"clean": "nx clear-cache && nx run-many --target=clean",
"dev": "nx run-many --target=dev",
"precommit": "lint-staged",
Expand Down
1 change: 1 addition & 0 deletions packages/w3c-context/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ The package includes the following pre-cached contexts:
- `https://trustvc.io/context/render-method-context.json` - Render Methods
- `https://trustvc.io/context/attachments-context.json` - Attachments
- `https://trustvc.io/context/qrcode-context.json` - QR Code
- `https://trustvc.io/context/opencerts-context.json` - OpenCerts Certificate
- `https://trustvc.io/context/bill-of-lading.json` - Bill of Lading
- `https://trustvc.io/context/bill-of-lading-carrier.json` - Bill of Lading Carrier
- `https://trustvc.io/context/coo.json` - Certificate of Origin
Expand Down
29 changes: 29 additions & 0 deletions packages/w3c-context/src/context/opencerts-demo-context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"@context": {
"@version": 1.1,
"@protected": true,
"OpenCertsCertificate": "https://example.com/#OpenCertsCertificate",
"name": "https://schema.org/name",
"description": "https://schema.org/description",
"issuedOn": "https://schema.org/dateIssued",
"admissionDate": "https://example.com/#admissionDate",
"graduationDate": "https://example.com/#graduationDate",
"recipient": "https://example.com/#recipient",
"nric": "https://example.com/#nric",
"course": "https://schema.org/course",
"transcript": "https://example.com/#transcript",
"grade": "https://example.com/#grade",
"courseCredit": "https://example.com/#courseCredit",
"courseCode": "https://example.com/#courseCode",
"examinationDate": "https://example.com/#examinationDate",
"semester": "https://example.com/#semester",
"additionalData": "https://example.com/#additionalData",
"merit": "https://example.com/#merit",
"studentId": "https://example.com/#studentId",
"transcriptId": "https://example.com/#transcriptId",
"certSignatories": "https://example.com/#certSignatories",
"signature": "https://example.com/#signature",
"position": "https://schema.org/jobTitle",
"organisation": "https://example.com/#organisation"
}
}
3 changes: 3 additions & 0 deletions packages/w3c-context/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import jwsV1 from '../context/jws-2020-v1.json';
import multikeyV1 from '../context/multikey-v1.json';
import promissoryNoteContext from '../context/promissory-note.json';
import qrCodeContext from '../context/qrcode-context.json';
import opencertsContext from '../context/opencerts-demo-context.json';
import renderContext from '../context/render-method-context.json';
import renderContextV2 from '../context/render-method-context-v2.json';
import statusList2021V1 from '../context/status-list-2021-v1.json';
Expand All @@ -38,6 +39,7 @@ export const RENDER_CONTEXT_URL = 'https://trustvc.io/context/render-method-cont
export const RENDER_CONTEXT_V2_URL = 'https://trustvc.io/context/render-method-context-v2.json';
export const ATTACHMENTS_CONTEXT_URL = 'https://trustvc.io/context/attachments-context.json';
export const QRCODE_CONTEXT_URL = 'https://trustvc.io/context/qrcode-context.json';
export const OPENCERTS_CONTEXT_URL = 'https://trustvc.io/context/opencerts-context.json';

export const BOL_CONTEXT_URL = 'https://trustvc.io/context/bill-of-lading.json';
export const BOLC_CONTEXT_URL = 'https://trustvc.io/context/bill-of-lading-carrier.json';
Expand Down Expand Up @@ -85,6 +87,7 @@ export const templateContexts: { [key: string]: Document } = {
[INVOICE_CONTEXT_URL]: invoiceContext,
[PROMISSORY_NOTE_CONTEXT_URL]: promissoryNoteContext,
[WAREHOUSE_RECEIPT_CONTEXT_URL]: warehouseReceiptContext,
[OPENCERTS_CONTEXT_URL]: opencertsContext,
};

export const CredentialContextVersion = {
Expand Down
21 changes: 14 additions & 7 deletions scripts/copy-files.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

### THIS SCRIPT IS NEEDED TO HOST THE CONTEXT FILES ON "https://trustvc.io/context/<file-name>" THROUGH NETLIFY
### THIS SCRIPT STAGES THE CONTEXT FILES IN ./public/context FOR DEPLOYMENT TO S3 + CLOUDFRONT

# Define the source and destination directories
SOURCE_DIR="./packages/w3c-context/src/context"
Expand All @@ -13,17 +13,24 @@ rm -rf ./public
mkdir -p "$DEST_DIR"

# List of files to copy
FILES=("attachments-context.json" "bill-of-lading.json" "bill-of-lading-carrier.json" "coo.json" "invoice.json" "promissory-note.json" "qrcode-context.json" "render-method-context.json" "transferable-records-context.json" "warehouse-receipt.json")
FILES=(
"attachments-context.json"
"bill-of-lading.json"
"bill-of-lading-carrier.json"
"coo.json"
"invoice.json"
"opencerts-demo-context.json"
"promissory-note.json"
"qrcode-context.json"
"render-method-context.json"
"transferable-records-context.json"
"warehouse-receipt.json"
)

# Copy each file
for FILE in "${FILES[@]}"; do
cp "$SOURCE_DIR/$FILE" "$DEST_DIR/"
done

echo "[[headers]]
for = \"/*\"
[headers.values]
Access-Control-Allow-Origin = \"*\"" > ./public/netlify.toml

# Optional: output a message when done
echo "Files have been copied to $DEST_DIR"
Loading