Skip to content

chore: updated tutorial workflow so it makes a PR instead of pushing … #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/actions/notify-slack-publish-status/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Slack Notify
13 changes: 13 additions & 0 deletions .github/actions/notify-slack-publish-status/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: 'Notify Slack Publish Status'
description: 'Notify Slack with the completion status of the publish action'
inputs:
message:
description: 'Message to send to Slack'
required: true
webhook-url:
description: 'Slack incoming webhook URL'
required: true
runs:
using: 'node20'
main: 'index.js'
52 changes: 52 additions & 0 deletions .github/actions/notify-slack-publish-status/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const core = require('@actions/core');
const webhook = core.getInput('webhook-url');

const run = async () => {
if (webhook) {
try {
await postSlackNotification();
} catch (e) {
console.log(e);
throw new Error(`failed because : ${e}`)
}
} else {
throw new Error('No SDK_PUBLISH_SLACK_WEBHOOK environment variable found');
}
}

const postSlackNotification = async () => {
const message = core.getInput('message');

if (!message) {
throw new Error('No message input found');
}

const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: message,
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: message,
}
}
]
}),
};

const response = await fetch(webhook, options);

if (response.status == 200) {
console.log('Posted message to Slack successfully');
} else {
throw new Error(`Failed to post message to Slack. Status code: ${response.status}`);
}
}

run();
15 changes: 15 additions & 0 deletions .github/actions/notify-slack-publish-status/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "notify-slack-publish-status",
"version": "1.0.0",
"description": "Sends a Slack notification with a publish status.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.10.1"
}
}
18 changes: 9 additions & 9 deletions .github/scripts/aggregate-passport-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ try {
// Find all feature group directories in _tutorials
const findFeatureGroupDirectories = () => {
const featureGroupDirs = [];

if (!fs.existsSync(TUTORIALS_DIR)) {
console.warn(`Tutorials directory does not exist: ${TUTORIALS_DIR}`);
return featureGroupDirs;
}

try {
}
try {
const dirs = fs.readdirSync(TUTORIALS_DIR, { withFileTypes: true });

dirs.forEach((dirent) => {
if (dirent.isDirectory()) {
featureGroupDirs.push(path.join(TUTORIALS_DIR, dirent.name));
}
});
} catch (err) {
}
});
} catch (err) {
console.warn(`Error reading tutorials directory ${TUTORIALS_DIR}: ${err.message}`);
}
}

return featureGroupDirs;
};
Expand Down Expand Up @@ -82,7 +82,7 @@ const processFeatureGroups = (featureGroupDirs) => {
if (!fs.existsSync(metadataPath)) {
console.warn(`No metadata.json found for feature group ${groupName} in ${groupDir}`);
return;
}
}

// Path to tutorial.md in this feature group directory
const tutorialPath = path.join(groupDir, 'tutorial.md');
Expand Down
22 changes: 12 additions & 10 deletions .github/scripts/process-passport-tutorials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ TUTORIALS_DIR="${PASSPORT_ROOT}/_tutorials~"

echo "Processing Passport tutorials..."

# Load features.json to get feature groups
FEATURES_JSON="${PASSPORT_ROOT}/features.json"
if [ ! -f "${FEATURES_JSON}" ]; then
echo "Error: features.json not found at ${FEATURES_JSON}"
exit 1
fi

# Create _tutorials directory in docs repo
DOCS_TUTORIALS_DIR="${DOCS_REPO_DIR}/docs/main/example/zkEVM/unity/passport-examples/_tutorials"
mkdir -p "${DOCS_TUTORIALS_DIR}"
# Base directory for usage guides in the docs repo
DOCS_USAGE_GUIDES_DIR="${DOCS_REPO_DIR}/docs/main/build/unity/usage/passport"

# Check if _tutorials~ directory exists
if [ ! -d "${TUTORIALS_DIR}" ]; then
Expand All @@ -40,12 +38,16 @@ else
if [ -f "${TUTORIAL_FILE}" ]; then
echo "Found tutorial for ${GROUP_NAME}"

# Define the destination directory for this feature group
DEST_GROUP_DIR="${DOCS_USAGE_GUIDES_DIR}/_tutorials"
mkdir -p "${DEST_GROUP_DIR}"

# Use the folder name directly for the destination filename
OUTPUT_FILENAME="${GROUP_NAME}.md"

# Copy the tutorial file
cp "${TUTORIAL_FILE}" "${DOCS_TUTORIALS_DIR}/${OUTPUT_FILENAME}"
echo "Copied ${TUTORIAL_FILE} to ${DOCS_TUTORIALS_DIR}/${OUTPUT_FILENAME}"
# Copy the tutorial file to its new group directory
cp "${TUTORIAL_FILE}" "${DEST_GROUP_DIR}/${OUTPUT_FILENAME}"
echo "Copied ${TUTORIAL_FILE} to ${DEST_GROUP_DIR}/${OUTPUT_FILENAME}"
else
echo "Warning: No tutorial.md found for feature group ${GROUP_NAME}"
fi
Expand All @@ -56,12 +58,12 @@ fi
JSON_FILE="./_parsed/passport-features.json"
if [ -f "${JSON_FILE}" ]; then
# Create directory for JSON file if it doesn't exist
JSON_DIR="${DOCS_REPO_DIR}/docs/main/example/zkEVM/unity/passport-examples"
JSON_DIR="${DOCS_REPO_DIR}/docs/main/build/unity/usage/passport"
mkdir -p "${JSON_DIR}"

# Copy JSON file
cp "${JSON_FILE}" "${JSON_DIR}/passport-features.json"
echo "Copied ${JSON_FILE} to ${JSON_DIR}/passport-features.json"
cp "${JSON_FILE}" "${JSON_DIR}/passport-examples.json"
echo "Copied ${JSON_FILE} to ${JSON_DIR}/passport-examples.json"
else
echo "Warning: No passport-features.json found at ${JSON_FILE}"
fi
Expand Down
47 changes: 33 additions & 14 deletions .github/workflows/publish-passport-tutorials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
repository: immutable/docs
token: ${{ secrets.UNITY_SDK_DOCS_WORKFLOW }}
path: imx-docs
ref: 'main'
ref: 'DVR-295-docs-restructure'

- name: Setup environment variables
run: echo "CLONE_DIR=./imx-docs" >> $GITHUB_ENV
Expand Down Expand Up @@ -65,20 +65,39 @@ jobs:
.github/scripts/process-passport-tutorials.sh
shell: bash

- name: Commit and Push Changes to Docs Repo
- name: Create Pull Request in Docs Repo
id: create_pr
run: |
cd "$CLONE_DIR"
if git status --porcelain | grep -q .; then
git add .

# Commit with reference to source commit
COMMIT_MSG="docs: Update Passport tutorials from Unity SDK (Ref: ${GITHUB_SHA::8})"
git commit -m "$COMMIT_MSG"

# Push to the target branch
git push -u origin main
echo "Successfully pushed Passport tutorial changes to docs repo"
else
if ! git status --porcelain | grep -q .; then
echo "No changes to commit"
echo "pr_url=" >> $GITHUB_OUTPUT
exit 0
fi
shell: bash

BRANCH_NAME="chore/unity-sdk-docs-update-${{ github.run_id }}"
git checkout -b $BRANCH_NAME

git add .
git commit -m "chore: example app usage guide updated"
git push -u origin $BRANCH_NAME
echo "Successfully pushed changes to docs repo on branch $BRANCH_NAME"

PR_URL=$(gh pr create \
--title "auto(unity-immutable-sdk): example app usage guide updated" \
--body "Automated PR from unity-immutable-sdk to update tutorials. This is safe for anyone to approve and merge." \
--base DVR-295-docs-restructure \
--repo immutable/docs)

echo "Successfully created PR in docs repo: $PR_URL"
echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.UNITY_SDK_DOCS_WORKFLOW }}
shell: bash

- name: Notify Slack
if: steps.create_pr.outputs.pr_url != ''
uses: ./.github/actions/notify-slack-publish-status
with:
message: 'New automated Unity SDK sample app tutorials PR is ready for review: ${{ steps.create_pr.outputs.pr_url }}'
webhook-url: ${{ secrets.SDK_DOCS_TUTORIALS_SLACK_WEBHOOK }}
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,11 @@ __pycache__/
*.pyc
.pytest_cache/

xcuserdata/
xcuserdata/

# Node.js dependencies and lock files
**/node_modules/
**/package-lock.json
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"title": "Immutable Passport Authentication",
"description": "Implement user authentication in Unity games with Immutable Passport SDK, supporting both Device Code and PKCE flows",
"keywords": ["Immutable", "SDK", "Authentication", "Login", "Logout", "Relogin", "Reconnect", "Passport", "Unity"],
"tech_stack": ["Unity", "C#", "UniTask", "Immutable Passport SDK"],
"title": "Authentication with Immutable Passport SDK",
"description": "Complete authentication system demonstrating Login, Logout, Relogin, and Reconnect features using PKCE flow for secure user authentication and session management in Unity games",
"keywords": ["Immutable", "SDK", "Authentication", "Login", "Logout", "Relogin", "Reconnect", "PKCE", "OAuth", "Passport", "Session Management"],
"tech_stack": ["Unity", "C#", "UniTask", "PKCE", "OAuth 2.0"],
"product": "Passport",
"programming_language": "C#"
"programming_language": "C#",
"sidebar_order": 20
}
Loading
Loading