Skip to content

Commit

Permalink
update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
eq19 committed Nov 20, 2024
1 parent a2ce403 commit 28b3a3f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 44 deletions.
40 changes: 15 additions & 25 deletions .github/entrypoint/artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions .github/entrypoint/gist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
43 changes: 31 additions & 12 deletions .github/entrypoint/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions .github/entrypoint/wiki.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ concurrency:
# ⚠️ Set token permissions
permissions: write-all

# 🕸️ Global Environment
env:
TARGET_REPOSITORY: ${{ vars.TARGET_REPOSITORY }}

jobs:
lexering:
strategy:
Expand Down Expand Up @@ -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')) ||
Expand Down

0 comments on commit 28b3a3f

Please sign in to comment.