"initialPrompt" parameter should be optional #16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "♻️,💻 App Directory Registration" | |
on: | |
workflow_call: | |
inputs: | |
repo: | |
required: true | |
type: string | |
description: 'Github repository of the app to register' | |
tag: | |
required: true | |
type: string | |
description: 'git tag of the app to register as its version' | |
container: | |
required: false | |
type: string | |
description: 'public container ID to include in the published app page' | |
workflow_dispatch: | |
inputs: | |
repo: | |
required: true | |
description: 'Github repository of the app to register' | |
tag: | |
required: true | |
description: 'git tag of the app to register as its version' | |
container: | |
required: false | |
description: 'public container ID to include in the published app page' | |
issues: | |
types: [opened] | |
env: | |
APP_DIR_REPO: 'clamsproject/apps' | |
jobs: | |
trigger: | |
name: "✅ Validate the trigger and set the variables" | |
runs-on: ubuntu-latest | |
outputs: | |
apprepo: ${{ steps.set_repo.outputs.apprepo }} | |
apptag: ${{ steps.set_repo.outputs.apptag }} | |
appcontainer: ${{ steps.set_repo.outputs.appcontainer }} | |
appissue: ${{ steps.set_repo.outputs.appissue }} | |
valid_trigger: ${{ steps.set_repo.outputs.valid_trigger }} | |
steps: | |
- name: "🏷 Set repo address and tag from submitted issue" | |
if: github.event_name == 'issues' && github.event.issue.title == 'CLAMS App Submission' | |
run: | | |
while IFS= read l; do | |
if [[ "$l" = NAME:* ]]; then | |
echo "app_repo=$(echo "$l" | awk -F ':' '{print $2}' | awk '{$1=$1;print $1}' | sed 's|^https://github.com/||g')" >> $GITHUB_ENV | |
elif [[ "$l" = TAG:* ]]; then | |
echo "app_tag=$(echo "$l" | awk -F ':' '{print $2}' | awk '{$1=$1;print $1}')" >> $GITHUB_ENV | |
elif [[ "$l" = CONTAINER:* ]]; then | |
echo "app_container=$(echo "$l" | awk -F ':' '{print $2}' | awk '{$1=$1;print $1}')" >> $GITHUB_ENV | |
fi | |
done <<< '${{ github.event.issue.body }}' | |
echo "app_issue=${{ github.event.issue.number }}" >> $GITHUB_ENV | |
- name: "🏷 Set repo address and tag from dispatch input" | |
if: github.event_name != 'issues' | |
run: | | |
echo "app_repo=$(echo ${{ inputs.repo }} | sed 's|^https://github.com/||g')" >> $GITHUB_ENV | |
echo "app_tag=${{ inputs.tag }}" >> $GITHUB_ENV | |
echo "app_container=${{ inputs.container }}" >> $GITHUB_ENV | |
echo "app_issue=0" >> $GITHUB_ENV | |
- name: "🕵 Sanity check for repo variables" | |
id: set_repo | |
run: | | |
if [ -z "${{ env.app_repo }}" ] || [ -z "${{ env.app_tag }}" ]; then | |
if [ ${{ github.event_name }} = 'issues' ] && [ ${{ github.event.issue.title }} = 'CLAMS App Submission' ]; then | |
echo "submitted issue is ill-formed" >&2 | |
exit 1 | |
else | |
echo "valid_trigger=false" >> $GITHUB_OUTPUT | |
fi | |
else | |
echo "valid_trigger=true" >> $GITHUB_OUTPUT | |
echo "apprepo=${{ env.app_repo }}" >> $GITHUB_OUTPUT | |
echo "apptag=${{ env.app_tag }}" >> $GITHUB_OUTPUT | |
echo "appcontainer=${{ env.app_container }}" >> $GITHUB_OUTPUT | |
echo "appsubmitter=${{ github.actor }}" >> $GITHUB_OUTPUT | |
echo "appissue=${{ env.app_issue }}" >> $GITHUB_OUTPUT | |
fi | |
generate: | |
name: "📝 Generate metadata files from app repo" | |
needs: [trigger] | |
if: needs.trigger.outputs.valid_trigger == 'true' | |
outputs: | |
appname: ${{ steps.create_branch.outputs.appname }} | |
appbranch: ${{ steps.create_branch.outputs.appbranch }} | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./main | |
steps: | |
- name: "🛍 Checkout directory repository" | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ env.APP_DIR_REPO }} | |
path: main | |
token: ${{ secrets.GH_CLAMSBOT_TOKEN }} | |
- name: "🐍 Setup Python" | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.8' | |
- name: "🛍 Checkout app repository" | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ needs.trigger.outputs.apprepo }} | |
ref: ${{ needs.trigger.outputs.apptag }} | |
path: app | |
- name: "💉 Install clams sdk" | |
working-directory: ./app | |
run: | | |
pip install $(grep clams-python requirements.* | sort -r | head -n1) | |
- name: "🏷 Generate app metadata" | |
working-directory: ./app | |
run: | | |
# echo first try to run metadata.py without full dependency install, then install the full dependencies when it fails | |
python ./metadata.py > ../main/metadata.json || for f in requirements.*; do pip install -r ${f}; done && python ./metadata.py > ../main/metadata.json | |
echo "{\"time\": \"$(date -Iseconds)\", \ | |
\"submitter\": \"${{ github.actor }}\", \ | |
\"image\": \"${{ needs.trigger.outputs.appcontainer }}\", \ | |
\"submitter\": \"${{ github.actor }}\" \ | |
}" \ | jq > ../main/submission.json | |
if [[ $(git cat-file -t ${{ needs.trigger.outputs.apptag }}) == tag ]]; then \ | |
cat ../main/submission.json | jq ". += {\"releasenotes\": $(git for-each-ref refs/tags/${{ needs.trigger.outputs.apptag }} --format='%(contents)' | jq -Rsa )}" > ../main/submission.json; fi | |
- name: "🏷 Prep more variables" | |
run: | | |
app_id=$( jq -r '.identifier' metadata.json ) | |
echo "app_fullid=$app_id" >> $GITHUB_ENV | |
echo "app_shortname=$( echo $app_id | rev | cut -d'/' -f2 | rev )" >> $GITHUB_ENV | |
echo "app_version=$( echo $app_id | rev | cut -d'/' -f1 | rev )" >> $GITHUB_ENV | |
- name: "🗞 Generate HTML and JSON publication" | |
run: | | |
python scripts/metadata_markdown.py > index.md | |
dir="docs/_apps/${{ env.app_shortname }}/${{ env.app_version }}" | |
mkdir -p $dir | |
cp {metadata,submission}.json index.md $dir/ | |
python scripts/index_page_data.py $dir | |
- name: "🫙 Commit and push docs with generated files" | |
id: create_branch | |
run: | | |
app_name="${{ env.app_shortname }}.${{ env.app_version }}" | |
branch_name="register/${{ needs.trigger.outputs.appissue }}-$app_name" | |
git config --local user.email "[email protected]" | |
git config --local user.name "clams-bot" | |
git checkout -b $branch_name | |
git add docs | |
git add -u docs | |
git commit -m "adding metadata of $app_name" | |
git push origin $branch_name | |
echo "appname=$app_name" >> $GITHUB_OUTPUT | |
echo "appbranch=$branch_name" >> $GITHUB_OUTPUT | |
send_pr: | |
name: "📦 Create PR to register the app" | |
runs-on: ubuntu-latest | |
needs: [trigger, generate] | |
steps: | |
- name: "✍️ Start a new pr" | |
uses: octokit/[email protected] | |
with: | |
route: POST /repos/${{ env.APP_DIR_REPO }}/pulls | |
title: 'App Submitted - ${{ needs.generate.outputs.appname }}' | |
head: '${{ needs.generate.outputs.appbranch }}' | |
base: main | |
body: | | |
${{ needs.trigger.outputs.appissue != 0 && format('( closes \#{0} .)', needs.trigger.outputs.appissue) || '(no connected issue)' }} | |
This PR registers the app ${{ needs.generate.outputs.appname }} from | |
https://github.com/${{ needs.trigger.outputs.apprepo }}/tree/${{ needs.trigger.outputs.apptag }}. | |
Carefully review the metadata before merging. If something is wrong with the metadata, please close the PR | |
and let the app developer know. | |
(submitted by @${{ github.actor }}) | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_CLAMSBOT_TOKEN }} |