Skip to content

Commit c3876bf

Browse files
Enable Alpha Publish
Add a CI/CD process that builds the SDK and publishes it to the alpha environment.
1 parent c20aafd commit c3876bf

1 file changed

Lines changed: 157 additions & 0 deletions

File tree

.github/workflows/Build.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Display Name of the workflow
2+
name: Build - GH Packages and Artifacts
3+
4+
# Event listeners for when the job should start execution
5+
on:
6+
# Triggers the workflow on push or pull request events to the main branch
7+
push:
8+
branches: [main]
9+
10+
# Allow this workflow to be called from another workflow
11+
workflow_call:
12+
inputs:
13+
correlationId:
14+
description: 'Correlates the origin job with the child instance since process start does not return an ID.'
15+
type: string
16+
required: false
17+
18+
jobs:
19+
# Generate the TypeScript SDK client code
20+
TypeScript-Build:
21+
# Generate each SDK client in a separate build process to speed up execution and publishing
22+
strategy:
23+
matrix:
24+
# Spec and SDK root locations
25+
specifications:
26+
- name: SHIELD
27+
sdkPath: 'src/shield/TypeScript'
28+
specPath: 'spec/SHIELD.json'
29+
- name: DataGateway
30+
sdkPath: 'src/dataGateway/TypeScript'
31+
specPath: 'spec/Data-Gateway.json'
32+
- name: UrlShortener
33+
sdkPath: 'src/urlShortener/TypeScript'
34+
specPath: 'spec/Url-Shortener.json'
35+
36+
# Display name of the job
37+
name: Generate NPM Packages
38+
39+
# Operating system filter for the runners
40+
runs-on: ubuntu-latest
41+
42+
# Allow single failures for SDK publish, e.g. SDG fail due to not getting an update but SHIELD goes through
43+
continue-on-error: true
44+
45+
# Sets the scopes available to the github_token injected to the GH Actions runner
46+
permissions:
47+
attestations: write
48+
contents: read
49+
packages: write
50+
51+
# Set of steps required to generate the API client for TypeScript
52+
steps:
53+
# Download all of the source code
54+
- name: Clone Repo Locally
55+
uses: actions/checkout@v7
56+
background: true
57+
58+
# Set up NodeJS on the build host
59+
- name: Setup Node.JS Runtime
60+
uses: actions/setup-node@v6
61+
background: true
62+
with:
63+
node-version: 24
64+
registry-url: https://npm.pkg.github.com
65+
scope: shi-corp
66+
67+
# Set up the socket firewall binary
68+
- name: Install - Socket Firewall
69+
uses: SocketDev/action@ba6de6cc0565af1f42295590380973573297e31f
70+
background: true
71+
with:
72+
mode: firewall-free
73+
74+
# Set up all of the supporting components for SDK generation
75+
- name: Initialize Kiota Binaries
76+
uses: microsoft/setup-kiota@v0.5.0
77+
background: true
78+
79+
# Bring job back to sync execution by awaiting for all async jobs to finish before continuing
80+
- name: Steps - Convert Back To Synchronous Execution - Build
81+
wait-all: true
82+
83+
# Update the NPM CLI to the latest available version
84+
- name: Update NPM CLI
85+
run: sfw npm install -g npm
86+
87+
# Install the dependencies needed to build the project
88+
- name: Install Build Dependencies
89+
run: sfw npm ci
90+
working-directory: ${{ matrix.specifications.sdkPath }}
91+
92+
# Cryptographically attest that packages haven't been tampered where supported
93+
- name: Attest Dependency Provenance
94+
run: npm audit signatures
95+
working-directory: ${{ matrix.specifications.sdkPath }}
96+
97+
# Generate the TypeScript SDK
98+
- name: Generate SDK Client Code via Kiota
99+
run: npm run generate:Sdk
100+
working-directory: ${{ matrix.specifications.sdkPath }}
101+
102+
# Generate the TypeScript SDK
103+
- name: Build Project
104+
run: npm run build:Prod
105+
working-directory: ${{ matrix.specifications.sdkPath }}
106+
107+
# Publish the artifact to NPM with attestation
108+
- name: Upload Package to NPM Registry
109+
run: npm publish --tag alpha
110+
working-directory: ${{ matrix.specifications.sdkPath }}
111+
112+
# Generate the NPM package for beta and stable publishing, if required
113+
- name: Generate NPM Package
114+
id: generate-package
115+
shell: bash
116+
working-directory: ${{ matrix.specifications.sdkPath }}
117+
run: |
118+
set -euo pipefail
119+
120+
PACK_OUTPUT_FILE="$RUNNER_TEMP/npm-pack-output.json"
121+
npm pack --json > "$PACK_OUTPUT_FILE" 2>&1
122+
sed -i '/^\[+\]/d' "$PACK_OUTPUT_FILE"
123+
124+
PACKAGE_FILE=$(node -e '
125+
const fs = require("fs");
126+
const filePath = process.argv[1];
127+
const contents = fs.readFileSync(filePath, "utf8")
128+
.split(/\r?\n/)
129+
.filter((line) => line.trim() && !line.trim().startsWith("[+]"))
130+
.join("\n");
131+
132+
const data = JSON.parse(contents);
133+
const filename = Array.isArray(data) ? data[0]?.filename : data?.filename;
134+
135+
if (!filename) {
136+
console.error("No filename found in npm pack output.");
137+
process.exit(1);
138+
}
139+
140+
console.log(filename);
141+
' "$PACK_OUTPUT_FILE")
142+
143+
echo "package-file=$PACKAGE_FILE" >> "$GITHUB_OUTPUT"
144+
145+
# Create an attestation for the generated NPM package to ensure integrity and authenticity
146+
- name: Attest NPM Package
147+
uses: actions/attest@v4
148+
with:
149+
subject-path: ${{ matrix.specifications.sdkPath }}/${{ steps.generate-package.outputs.package-file }}
150+
151+
# Upload the compiled HTML as an artifact for future consumption
152+
- name: Upload a Build Artifact
153+
uses: actions/upload-artifact@v7
154+
with:
155+
name: ${{ matrix.specifications.name }}
156+
if-no-files-found: error
157+
path: ${{ matrix.specifications.sdkPath }}/${{ steps.generate-package.outputs.package-file }}

0 commit comments

Comments
 (0)