From 28b3a3f18a76264d0aecea724edeffd614b445df Mon Sep 17 00:00:00 2001 From: eq19 Date: Wed, 20 Nov 2024 03:03:50 +0000 Subject: [PATCH] update workflows --- .github/entrypoint/artifact.sh | 40 ++++++++++++------------------- .github/entrypoint/gist.sh | 5 ++-- .github/entrypoint/init.sh | 43 ++++++++++++++++++++++++---------- .github/entrypoint/wiki.sh | 4 ++++ .github/workflows/main.yml | 10 ++++---- 5 files changed, 58 insertions(+), 44 deletions(-) diff --git a/.github/entrypoint/artifact.sh b/.github/entrypoint/artifact.sh index 52cd3cd8a6..8de09fca53 100755 --- a/.github/entrypoint/artifact.sh +++ b/.github/entrypoint/artifact.sh @@ -11,7 +11,7 @@ set_target() { echo "maps, feed, lexer, parser, syntax, grammar" > ${RUNNER_TEMP}/pinned_repos else QUERY='{"query":"{\n organization(login: \"'${OWNER}'\") {\n pinnedItems(first: 6, types: REPOSITORY) {\n nodes {\n ... on Repository {\n name\n }\n }\n }\n }\n}"' - curl -s -X POST "${GITHUB_GRAPHQL_URL}" -H "Authorization: bearer ${TOKEN}" --data-raw "${QUERY}" | jq --raw-output '.data.organization.pinnedItems.nodes[].name' | yq eval -P | sed "s/ /, /g" > ${RUNNER_TEMP}/pinned_repos + curl -s -X POST "${GITHUB_GRAPHQL_URL}" -H "Authorization: bearer ${GH_TOKEN}" --data-raw "${QUERY}" | jq --raw-output '.data.organization.pinnedItems.nodes[].name' | yq eval -P | sed "s/ /, /g" > ${RUNNER_TEMP}/pinned_repos sed -i "1s|^|maps, feed, lexer, parser, syntax, grammar, |" ${RUNNER_TEMP}/pinned_repos fi IFS=', '; array=($(cat ${RUNNER_TEMP}/pinned_repos)) @@ -21,7 +21,7 @@ set_target() { echo "[" > ${RUNNER_TEMP}/orgs.json for ((i=0; i < ${#array[@]}; i++)); do QUERY='{"query":"{\n organization(login: \"'${array[$i]}'\") {\n pinnedItems(first: 6, types: REPOSITORY) {\n nodes {\n ... on Repository {\n name\n }\n }\n }\n }\n}"' - IFS=', '; pr=($(curl -s -X POST "${GITHUB_GRAPHQL_URL}" -H "Authorization: bearer ${TOKEN}" --data-raw "${QUERY}" | jq --raw-output '.data.organization.pinnedItems.nodes[].name' | yq eval -P | sed "s/ /, /g")) + IFS=', '; pr=($(curl -s -X POST "${GITHUB_GRAPHQL_URL}" -H "Authorization: bearer ${GH_TOKEN}" --data-raw "${QUERY}" | jq --raw-output '.data.organization.pinnedItems.nodes[].name' | yq eval -P | sed "s/ /, /g")) gh api -H "${HEADER}" /orgs/${array[$i]} | jq '. + {"key1": ["maps","feed","lexer","parser","syntax","grammar"]} + {"key2": ["'${pr[0]}'","'${pr[1]}'","'${pr[2]}'","'${pr[3]}'","'${pr[4]}'","'${pr[5]}'"]}' >> ${RUNNER_TEMP}/orgs.json @@ -42,7 +42,7 @@ set_target() { echo "maps, feed, lexer, parser, syntax, grammar" > ${RUNNER_TEMP}/pinned_repos else QUERY='{"query":"{\n organization(login: \"'${ENTRY}'\") {\n pinnedItems(first: 6, types: REPOSITORY) {\n nodes {\n ... on Repository {\n name\n }\n }\n }\n }\n}"' - curl -s -X POST "${GITHUB_GRAPHQL_URL}" -H "Authorization: bearer ${TOKEN}" --data-raw "${QUERY}" | jq --raw-output '.data.organization.pinnedItems.nodes[].name' | yq eval -P | sed "s/ /, /g" > ${RUNNER_TEMP}/pinned_repos + curl -s -X POST "${GITHUB_GRAPHQL_URL}" -H "Authorization: bearer ${GH_TOKEN}" --data-raw "${QUERY}" | jq --raw-output '.data.organization.pinnedItems.nodes[].name' | yq eval -P | sed "s/ /, /g" > ${RUNNER_TEMP}/pinned_repos sed -i "1s|^|maps, feed, lexer, parser, syntax, grammar, |" ${RUNNER_TEMP}/pinned_repos fi fi @@ -79,9 +79,7 @@ jekyll_build() { echo -e "\n$hr\nCONFIG\n$hr" - [[ $1 == *"github.io"* ]] && OWNER=$2 - echo 'repo='${OWNER}/$1 >> ${GITHUB_OUTPUT} - echo 'TARGET_REPOSITORY='${OWNER}/$1 >> ${GITHUB_ENV} + [[ $1 == *"github.io"* ]] && OWNER=$2 if [[ $1 != "eq19.github.io" ]]; then SITEID=$(( $3 + 2 )); else SITEID=1; fi if [[ "${OWNER}" == "eq19" ]]; then @@ -97,35 +95,27 @@ jekyll_build() { sed -i "1s|^|repository: ${OWNER}/$1\n|" ${RUNNER_TEMP}/_config.yml [[ $1 != *"github.io"* ]] && sed -i "1s|^|baseurl: /$1\n|" ${RUNNER_TEMP}/_config.yml + FOLDER="span$(( 17 - $3 ))" + TARGET_REPOSITORY=${OWNER}/$1 + gh variable set FOLDER --body "$FOLDER" + echo 'FOLDER='${FOLDER} >> ${RUNNER_TEMP}/.env + echo 'repo='${TARGET_REPOSITORY} >> ${GITHUB_OUTPUT} + gh variable set TARGET_REPOSITORY --body "$TARGET_REPOSITORY" + echo 'TARGET_REPOSITORY='${TARGET_REPOSITORY} >> ${GITHUB_ENV} + sed -i "1s|^|title: eQuantum\n|" ${RUNNER_TEMP}/_config.yml - FOLDER="span$(( 17 - $3 ))" && sed -i "1s|^|span: ${FOLDER}\n|" ${RUNNER_TEMP}/_config.yml + sed -i "1s|^|span: ${FOLDER}\n|" ${RUNNER_TEMP}/_config.yml sed -i "1s|^|user: ${USER}\n|" ${RUNNER_TEMP}/_config.yml - sed -i "1s|^|id: ${SITEID}\n|" ${RUNNER_TEMP}/_config.yml + echo 'ID='${SITEID} >> ${GITHUB_ENV} cat ${RUNNER_TEMP}/_config.yml - echo -e "\n$hr\nWORKSPACE\n$hr" - gist.sh $1 ${OWNER} ${FOLDER} - find ${RUNNER_TEMP}/gistdir -type d -name .git -prune -exec rm -rf {} \; - - cd ${RUNNER_TEMP}/workdir && mv -f ${RUNNER_TEMP}/_config.yml . - rm -rf ${RUNNER_TEMP}/Sidebar.md && cp _Sidebar.md ${RUNNER_TEMP}/Sidebar.md - sed -i 's/0. \[\[//g' ${RUNNER_TEMP}/Sidebar.md && sed -i 's/\]\]//g' ${RUNNER_TEMP}/Sidebar.md - - echo -e "\n$hr\nSPIN\n$hr" - find . -iname '*.md' -print0 | sort -zn | xargs -0 -I '{}' front.sh '{}' - find . -type d -name "${FOLDER}" -prune -exec sh -c 'cat ${RUNNER_TEMP}/README.md >> $1/README.md' sh {} \; - - cp -R ${RUNNER_TEMP}/gistdir/* . && mkdir ${RUNNER_TEMP}/workdir/_data - #echo 'orgs_json='$(cat ${RUNNER_TEMP}/orgs.json) >> ${GITHUB_OUTPUT} - mv -f ${RUNNER_TEMP}/*.json ${RUNNER_TEMP}/workdir/_data/ - } # Get structure on gist files PATTERN='sort_by(.created_at)|.[] | select(.public == true).files.[] | select(.filename != "README.md").raw_url' -HEADER="Accept: application/vnd.github+json" && echo ${TOKEN} | gh auth login --with-token +HEADER="Accept: application/vnd.github+json" && echo ${GH_TOKEN} | gh auth login --with-token gh api -H "${HEADER}" "/users/eq19/gists" --jq "${PATTERN}" > ${RUNNER_TEMP}/gist_files # Capture the string and return status diff --git a/.github/entrypoint/gist.sh b/.github/entrypoint/gist.sh index cad9efcfcf..58272d1e14 100755 --- a/.github/entrypoint/gist.sh +++ b/.github/entrypoint/gist.sh @@ -2,7 +2,7 @@ rm -rf ${RUNNER_TEMP}/*dir -WIKI=https://github.com/$2/$1.wiki.git +WIKI=https://github.com/$1.wiki.git BASE=https://github.com/eq19/eq19.github.io.wiki.git #git ls-remote ${WIKI} > /dev/null 2>&1 @@ -41,6 +41,5 @@ find ${RUNNER_TEMP}/gistdir -type f -name 'spin_*.txt' | sort -n -t _ -k 2 | wh if [[ "${WIKI}" != "${BASE}" ]]; then git clone $WIKI ${RUNNER_TEMP}/wikidir mv -f ${RUNNER_TEMP}/wikidir/Home.md ${RUNNER_TEMP}/wikidir/README.md - echo $3 - find ${RUNNER_TEMP}/gistdir -type d -name "$3" -prune -exec sh -c 'wiki.sh "$1"' sh {} \; + find ${RUNNER_TEMP}/gistdir -type d -name "$2" -prune -exec sh -c 'wiki.sh "$1"' sh {} \; fi diff --git a/.github/entrypoint/init.sh b/.github/entrypoint/init.sh index 18c0505d63..562b735e67 100755 --- a/.github/entrypoint/init.sh +++ b/.github/entrypoint/init.sh @@ -8,7 +8,7 @@ git config --global user.name "${GITHUB_ACTOR}" git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" git config --global --add safe.directory "${GITHUB_WORKSPACE}" -#[[ "$RUNNER_OS" == "Windows" ]] && git config --global core.autocrlf true +[[ "$RUNNER_OS" == "Windows" ]] && YQ=$(choco install yq) [[ "$RUNNER_OS" == "Windows" ]] && git config --global core.safecrlf false git config --global credential.helper store @@ -19,20 +19,14 @@ REMOTE_REPO="https://${GITHUB_ACTOR}:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY} API_URL="https://api.github.com/users/eq19/events/public" LATEST_COMMIT=$(curl -s $API_URL | jq ".[0].payload.commits[0].message") -if [[ $? -eq 0 ]]; then - if [[ -z "$LATEST_COMMIT" ]]; then - echo 'LATEST_COMMIT="update by workspace"' >> ${GITHUB_ENV} - elif [[ "$LATEST_COMMIT" == null ]]; then - echo 'LATEST_COMMIT="update by workspace"' >> ${GITHUB_ENV} - else - echo 'LATEST_COMMIT='$LATEST_COMMIT >> ${GITHUB_ENV} - fi -else +if [[ -z "$LATEST_COMMIT" ]] || [[ "$LATEST_COMMIT" == "null" ]]; then echo 'LATEST_COMMIT="update by workspace"' >> ${GITHUB_ENV} +else + echo 'LATEST_COMMIT='$LATEST_COMMIT >> ${GITHUB_ENV} fi if [[ "${JOB_ID}" == "1" ]]; then - + cd "${GITHUB_WORKSPACE}" && rm -rf .github cp -r /home/runner/work/_actions/eq19/eq19/v1/.github . chown -R "$(whoami)" .github @@ -48,8 +42,33 @@ if [[ -z ${PASS} ]] || [[ "${PASS}" == "true" ]]; then echo -e "\n$hr\nENVIRONTMENT\n$hr" echo 'TARGET_REPO='${TARGET_REPO} >> ${GITHUB_ENV} echo 'REMOTE_REPO='${REMOTE_REPO} >> ${GITHUB_ENV} + + if [[ -f _config.yml ]]; then + FOLDER=$(yq '.span' _config.yml) + export FOLDER=$(eval echo $FOLDER) + elif [[ -f /home/runner/_site/.env ]]; then + set -a && . /home/runner/_site/.env && set +a + fi printenv | sort - echo -e "\n$hr\nGITHUB CONTEXT\n$hr" +fi +if [[ "${JOB_ID}" == "3" ]]; then + + echo -e "\n$hr\nWORKSPACE\n$hr" + gist.sh ${TARGET_REPOSITORY} ${FOLDER} + find ${RUNNER_TEMP}/gistdir -type d -name .git -prune -exec rm -rf {} \; + + mv -f ${RUNNER_TEMP}/workdir/* /home/runner/_site/ + rm -rf ${RUNNER_TEMP}/Sidebar.md && cp _Sidebar.md ${RUNNER_TEMP}/Sidebar.md + sed -i 's/0. \[\[//g' ${RUNNER_TEMP}/Sidebar.md && sed -i 's/\]\]//g' ${RUNNER_TEMP}/Sidebar.md + + cd /home/runner/_site && cp -R ${RUNNER_TEMP}/gistdir/* . + find . -iname '*.md' -print0 | sort -zn | xargs -0 -I '{}' front.sh '{}' + find . -type d -name "${FOLDER}" -prune -exec sh -c 'cat ${RUNNER_TEMP}/README.md >> $1/README.md' sh {} \; + +fi + +if [[ -z ${PASS} ]] || [[ "${PASS}" == "true" ]]; then + echo -e "\n$hr\nGITHUB CONTEXT\n$hr" fi diff --git a/.github/entrypoint/wiki.sh b/.github/entrypoint/wiki.sh index 7af5fb0458..b0ed5e866e 100755 --- a/.github/entrypoint/wiki.sh +++ b/.github/entrypoint/wiki.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +hr='------------------------------------------------------------------------------------' + gh gist clone 0ce5848f7ad62dc46dedfaa430069857 $1/identition/span1 gh gist clone b32915925d9d365e2e9351f0c4ed786e $1/identition/span2 gh gist clone 88d09204b2e5986237bd66d062406fde $1/identition/span3 @@ -30,4 +32,6 @@ rm -rf ${RUNNER_TEMP}/Sidebar.md && cp $1/_Sidebar.md ${RUNNER_TEMP}/Sidebar.md sed -i 's/0. \[\[//g' ${RUNNER_TEMP}/Sidebar.md && sed -i 's/\]\]//g' ${RUNNER_TEMP}/Sidebar.md find $1 -iname '*.md' -print0 | sort -zn | xargs -0 -I '{}' front.sh '{}' + +echo -e "\n$hr\nSPIN\n$hr" cat ${RUNNER_TEMP}/spin.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a27e1ce274..ff92df2d57 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,6 +31,10 @@ concurrency: # ⚠️ Set token permissions permissions: write-all +# 🕸️ Global Environment +env: + TARGET_REPOSITORY: ${{ vars.TARGET_REPOSITORY }} + jobs: lexering: strategy: @@ -116,11 +120,9 @@ jobs: max-parallel: ${{ contains(needs.*.result, 'success') && 1 || 2 }} fail-fast: ${{ contains(needs.*.result, 'success') && false || true }} - # 🕸️ Global Environment env: - PASS: ${{ contains(needs.*.result, 'success') && true || false }} - TARGET_REPOSITORY: '${{ needs.lexering.outputs.target }}' - IP_ADDRESS: '${{ needs.lexering.outputs.address }}' + IP_ADDRESS: '${{ needs.lexering.outputs.address }}' + PASS: ${{ contains(needs.*.result, 'success') && true || false }} # ✔️ Completeness status if: ${{ (always() && contains(needs.*.result, 'success')) ||