Skip to content

Commit 6323bd2

Browse files
fix: updated tutorial workflow
1 parent 63dada5 commit 6323bd2

File tree

1 file changed

+22
-236
lines changed

1 file changed

+22
-236
lines changed

.github/workflows/publish-passport-tutorials.yml

Lines changed: 22 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ on:
1010
- 'sample/Assets/Scripts/Passport/**/tutorial.md'
1111
- 'sample/Assets/Scripts/Passport/**/metadata.json'
1212
- 'sample/Assets/Scripts/Passport/features.json'
13-
- '.github/scripts/aggregate-passport-metadata.js'
14-
- '.github/scripts/process-passport-tutorials.sh'
15-
- '.github/workflows/publish-passport-tutorials.yml'
13+
1614
# Allow manual triggering
1715
workflow_dispatch:
1816

@@ -26,228 +24,25 @@ jobs:
2624
runs-on: ubuntu-latest
2725
steps:
2826
- name: Checkout Unity SDK Repo
29-
uses: actions/checkout@v3
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
3028
with:
3129
fetch-depth: 0
32-
ref: ${{ github.ref }}
33-
34-
- name: Create Script Directories
35-
run: |
36-
mkdir -p .github/scripts
37-
mkdir -p _parsed
38-
39-
- name: Create Aggregation Script
40-
run: |
41-
cat > .github/scripts/aggregate-passport-metadata.js << 'EOF'
42-
#!/usr/bin/env node
43-
44-
const fs = require('fs');
45-
const path = require('path');
46-
const { execSync } = require('child_process');
47-
48-
// Configuration
49-
const PASSPORT_ROOT = './sample/Assets/Scripts/Passport';
50-
const OUTPUT_DIR = './_parsed';
51-
const OUTPUT_FILE = path.join(OUTPUT_DIR, 'passport-features.json');
52-
const FEATURES_JSON_PATH = path.join(PASSPORT_ROOT, 'features.json');
5330

54-
// Ensure output directory exists
55-
if (!fs.existsSync(OUTPUT_DIR)) {
56-
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
57-
}
58-
59-
console.log('Processing Passport features metadata...');
60-
61-
// Load features.json to map script files to feature names
62-
let featuresMap = {};
63-
try {
64-
const featuresContent = fs.readFileSync(FEATURES_JSON_PATH, 'utf8');
65-
const featuresJson = JSON.parse(featuresContent);
66-
67-
// Create mapping of script filename to feature name
68-
featuresJson.features.forEach(feature => {
69-
const [featureName, scriptFile] = Object.entries(feature)[0];
70-
featuresMap[scriptFile] = featureName;
71-
});
72-
} catch (error) {
73-
console.error(`Error reading features.json: ${error.message}`);
74-
process.exit(1);
75-
}
76-
77-
// Find all metadata.json files
78-
const findMetadataFiles = () => {
79-
const result = execSync(`find "${PASSPORT_ROOT}" -name "metadata.json" -type f`).toString().trim();
80-
return result.split('\n').filter(Boolean);
81-
};
82-
83-
// Process metadata files
84-
const processMetadataFiles = (metadataFiles) => {
85-
const features = [];
86-
87-
metadataFiles.forEach(metadataFile => {
88-
console.log(`Processing ${metadataFile}`);
89-
90-
// Extract feature directory
91-
const featureDir = path.dirname(metadataFile);
92-
93-
// Find script file in this directory
94-
let featureName = '';
95-
try {
96-
const dirFiles = fs.readdirSync(featureDir);
97-
const scriptFiles = dirFiles.filter(file => file.endsWith('.cs'));
98-
99-
if (scriptFiles.length > 0) {
100-
// Look up the feature name in featuresMap
101-
const scriptFile = scriptFiles[0];
102-
featureName = featuresMap[scriptFile] || '';
103-
}
104-
105-
// If not found in features.json, fallback to directory name
106-
if (!featureName) {
107-
console.warn(`Feature for script in ${featureDir} not found in features.json, using directory name`);
108-
featureName = path.basename(featureDir);
109-
}
110-
} catch (error) {
111-
console.warn(`Error processing directory ${featureDir}: ${error.message}`);
112-
featureName = path.basename(featureDir);
113-
}
114-
115-
console.log(`Feature name: ${featureName}`);
116-
117-
// Read and process metadata
118-
try {
119-
const metadataContent = fs.readFileSync(metadataFile, 'utf8');
120-
const metadata = JSON.parse(metadataContent);
121-
122-
// Add feature name to metadata
123-
metadata.name = featureName;
124-
features.push(metadata);
125-
} catch (error) {
126-
console.error(`Error processing metadata file ${metadataFile}: ${error.message}`);
127-
}
128-
});
129-
130-
return features;
131-
};
132-
133-
// Main execution
134-
const metadataFiles = findMetadataFiles();
135-
const features = processMetadataFiles(metadataFiles);
136-
137-
// Create the final passport-features.json
138-
const passportFeatures = { features };
139-
fs.writeFileSync(OUTPUT_FILE, JSON.stringify(passportFeatures, null, 2));
140-
141-
console.log(`Created ${OUTPUT_FILE}`);
142-
EOF
143-
chmod +x .github/scripts/aggregate-passport-metadata.js
144-
145-
- name: Create Tutorial Processing Script
146-
run: |
147-
cat > .github/scripts/process-passport-tutorials.sh << 'EOF'
148-
#!/bin/bash
149-
150-
set -e
151-
set -x
152-
153-
# Directory where docs repo is cloned
154-
DOCS_REPO_DIR=${CLONE_DIR:-"./imx-docs"}
155-
156-
# Root of the Passport features
157-
PASSPORT_ROOT="./sample/Assets/Scripts/Passport"
158-
159-
echo "Processing Passport tutorials..."
160-
161-
# Load features.json to map script files to feature names
162-
FEATURES_JSON="$PASSPORT_ROOT/features.json"
163-
if [ ! -f "$FEATURES_JSON" ]; then
164-
echo "Error: features.json not found at $FEATURES_JSON"
165-
exit 1
166-
fi
167-
168-
# Check and create required directories in docs repo
169-
BASE_DIR="$DOCS_REPO_DIR/docs/main/example/zkevm"
170-
171-
# Create unity directory if it doesn't exist
172-
UNITY_DIR="$BASE_DIR/unity"
173-
if [ ! -d "$UNITY_DIR" ]; then
174-
echo "Creating unity directory at $UNITY_DIR"
175-
mkdir -p "$UNITY_DIR"
176-
fi
177-
178-
# Create passport directory if it doesn't exist
179-
PASSPORT_DIR="$UNITY_DIR/passport"
180-
if [ ! -d "$PASSPORT_DIR" ]; then
181-
echo "Creating passport directory at $PASSPORT_DIR"
182-
mkdir -p "$PASSPORT_DIR"
183-
fi
184-
185-
# Create _tutorials directory
186-
TUTORIALS_DIR="$PASSPORT_DIR/_tutorials"
187-
mkdir -p "$TUTORIALS_DIR"
188-
189-
# Find all tutorial.md files
190-
TUTORIAL_FILES=$(find "$PASSPORT_ROOT" -name "tutorial.md" -type f)
191-
192-
for TUTORIAL_FILE in $TUTORIAL_FILES; do
193-
echo "Processing $TUTORIAL_FILE"
194-
195-
# Extract feature directory
196-
FEATURE_DIR=$(dirname "$TUTORIAL_FILE")
197-
198-
# Try to find script file in this directory
199-
SCRIPT_FILE=$(find "$FEATURE_DIR" -name "*.cs" -type f | head -n 1)
200-
if [ -z "$SCRIPT_FILE" ]; then
201-
echo "Warning: No script file found in $FEATURE_DIR, using directory name"
202-
FEATURE_NAME=$(basename "$FEATURE_DIR")
203-
else
204-
# Extract script filename
205-
SCRIPT_FILENAME=$(basename "$SCRIPT_FILE")
206-
207-
# Look up the feature name in features.json
208-
FEATURE_NAME=$(jq -r ".features[] | to_entries[] | select(.value == \"$SCRIPT_FILENAME\") | .key" "$FEATURES_JSON")
209-
210-
# If not found in features.json, fallback to directory name
211-
if [ -z "$FEATURE_NAME" ] || [ "$FEATURE_NAME" == "null" ]; then
212-
echo "Warning: Feature for script $SCRIPT_FILENAME not found in features.json, using directory name"
213-
FEATURE_NAME=$(basename "$FEATURE_DIR")
214-
fi
215-
fi
216-
217-
echo "Feature name: $FEATURE_NAME"
218-
219-
# Copy and rename tutorial file
220-
cp "$TUTORIAL_FILE" "$TUTORIALS_DIR/${FEATURE_NAME}.md"
221-
echo "Copied $TUTORIAL_FILE to $TUTORIALS_DIR/${FEATURE_NAME}.md"
222-
done
223-
224-
# Copy the generated JSON file
225-
JSON_FILE="./_parsed/passport-features.json"
226-
if [ -f "$JSON_FILE" ]; then
227-
# Copy JSON file to the passport directory
228-
cp "$JSON_FILE" "$PASSPORT_DIR/passport-features.json"
229-
echo "Copied $JSON_FILE to $PASSPORT_DIR/passport-features.json"
230-
else
231-
echo "Warning: No passport-features.json found at $JSON_FILE"
232-
fi
233-
234-
echo "Passport tutorial processing complete."
235-
EOF
236-
chmod +x .github/scripts/process-passport-tutorials.sh
31+
- name: Create Parsed Directory
32+
run: mkdir -p _parsed
23733

23834
- name: Checkout Docs Repo
239-
uses: actions/checkout@v3
35+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
24036
with:
241-
repository: immutable/imx-docs
242-
token: ${{ secrets.DOCS_REPO_PAT }}
37+
repository: immutable/docs
38+
token: ${{ secrets.UNITY_IMMUTABLE_SDK_GITHUB_TOKEN }}
24339
path: imx-docs
24440
ref: 'DVR-425-unity-sample-app-tutorial'
24541

24642
- name: Setup environment variables
247-
run: |
248-
echo "CLONE_DIR=./imx-docs" >> $GITHUB_ENV
43+
run: echo "CLONE_DIR=./imx-docs" >> $GITHUB_ENV
24944

250-
- name: Setup Github
45+
- name: Setup Git
25146
run: |
25247
git config --global user.name "${GITHUB_ACTOR}"
25348
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
@@ -257,42 +52,33 @@ jobs:
25752
sudo apt-get update
25853
sudo apt-get install -y jq
25954
260-
- name: Generate Passport Features JSON
261-
run: |
262-
node ./.github/scripts/aggregate-passport-metadata.js
263-
shell: bash
264-
26555
- name: Process Passport Tutorials
26656
run: |
267-
./.github/scripts/process-passport-tutorials.sh
268-
shell: bash
269-
270-
- name: List Generated Files
271-
run: |
272-
echo "Generated passport-features.json:"
273-
ls -la _parsed/
57+
# Make scripts executable
58+
chmod +x .github/scripts/aggregate-passport-metadata.js
59+
chmod +x .github/scripts/process-passport-tutorials.sh
27460
275-
echo "Generated tutorial files:"
276-
ls -la imx-docs/docs/main/example/zkevm/unity/passport/_tutorials/
61+
# Generate aggregated JSON file
62+
node .github/scripts/aggregate-passport-metadata.js
27763
278-
echo "Content of passport-features.json:"
279-
cat _parsed/passport-features.json | jq .
64+
# Process tutorials and copy to docs repo
65+
.github/scripts/process-passport-tutorials.sh
66+
shell: bash
28067

28168
- name: Commit and Push Changes to Docs Repo
28269
run: |
28370
cd "$CLONE_DIR"
284-
# Check if there are changes to commit
28571
if git status --porcelain | grep -q .; then
286-
# Add all changes
28772
git add .
28873
289-
# Commit the changes
290-
git commit -m "Update Passport tutorials from Unity SDK repo"
74+
# Commit with reference to source commit
75+
COMMIT_MSG="docs: Update Passport tutorials from Unity SDK (Ref: ${GITHUB_SHA::8})"
76+
git commit -m "$COMMIT_MSG"
29177
292-
# Push to the target branch (always DVR-425-unity-sample-app-tutorial for now)
78+
# Push to the target branch
29379
git push -u origin DVR-425-unity-sample-app-tutorial
29480
echo "Successfully pushed Passport tutorial changes to docs repo"
29581
else
29682
echo "No changes to commit"
29783
fi
298-
shell: bash
84+
shell: bash

0 commit comments

Comments
 (0)