Build #12619
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: Build | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "10 */4 * * *" | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Dependence | |
run: sudo apt-get install -y rename | |
- name: Import ssh private key | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_KEY }}" | sed 's/\\n/\n/g' > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
- name: Git config | |
run: | | |
git config --global user.email "43134606+Ryanjiena@users.noreply.github.com" | |
git config --global user.name "Ryanjiena" | |
# https://stackoverflow.com/questions/13363553/git-error-host-key-verification-failed-when-connecting-to-remote-repository/13364116#13364116 | |
# ssh-keygen -R jihulab.com | |
ssh-keyscan -t rsa jihulab.com >> ~/.ssh/known_hosts | |
# - name: Import GPG key | |
# uses: crazy-max/ghaction-import-gpg@v6 | |
# with: | |
# gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
# git_config_global: true | |
# git_user_signingkey: true | |
# git_commit_gpgsign: true | |
- name: "Build" | |
env: | |
github_token: ${{ secrets.GH_TOKEN }} | |
run: | | |
#!/usr/bin/env bash | |
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin | |
export PATH | |
# set -euxo pipefail | |
DATE="$(echo $(TZ=UTC date '+%Y-%m-%d %H:%M:%S'))" | |
USER=$(whoami) | |
TMP_DIR="${TMP_DIR:-$(mktemp -d /tmp/breathe.XXXX)}" | |
LOG_FILE="${LOG_FILE:-${TMP_DIR}/build.log}" | |
head_start="<\!--ts-->" | |
head_end="<\!--te-->" | |
repoArr=("jonz94/scoop-sarasa-nerd-fonts@sarasa-nerd-fonts@master" | |
"kodybrown/scoop-nirsoft@nirsoft@master" | |
"matthewjberger/scoop-nerd-fonts@nerd-fonts@master" | |
"ScoopInstaller/Java@java@master" | |
"ScoopInstaller/Main@main@master" | |
"ScoopInstaller/Nonportable@nonportable@master" | |
"ScoopInstaller/Versions@versions@master" | |
"ScoopInstaller/Extras@extras@master" | |
# "Ryanjiena/Meta@meta@main" | |
"chawyehsu/dorado@dorado@master") | |
# init | |
function init() { | |
git clone -q --depth=1 --branch="main" https://Ryanjiena:${github_token}@github.com/Ryanjiena/breathe.git "${TMP_DIR}/breathe" | |
cd "${TMP_DIR}/breathe/" | |
if [ -d "bucket" ]; then | |
rm -rf bin bucket scripts | |
fi | |
mkdir bin bucket scripts | |
} | |
# build | |
function build() { | |
manifest_badge="| Bucket | Manifest |\n| :--- | :--- |\n" | |
for ((i = 0; i < ${#repoArr[@]}; i++)); do | |
local repo=$(echo "${repoArr[i]}" | awk -F'@' '{print $1}') | |
local repo_name=$(echo "${repoArr[i]}" | awk -F'@' '{print $2}') | |
local repo_branch=$(echo "${repoArr[i]}" | awk -F'@' '{print $3}') | |
if [[ "${repo_name}" != "meta" ]]; then | |
git clone -q --depth=1 --branch="${repo_branch}" "https://github.com/${repo}.git" "${TMP_DIR}/${repo_name}" | |
else | |
git clone -q --depth=1 --branch="${repo_branch}" "https://Ryanjiena:${github_token}@github.com/${repo}.git" "${TMP_DIR}/${repo_name}" | |
fi | |
cd "${TMP_DIR}/${repo_name}/bucket" | |
manifest_num="$(ls *.json | wc -l)" | |
manifest_badge="${manifest_badge} | [${repo}](https://github.com/${repo}.git) | [![${repo} badge](https://img.shields.io/static/v1?label=${repo}&message=${manifest_num}&color=green)](https://github.com/${repo}.git) |\n" | |
# rename manifest | |
# https://unix.stackexchange.com/a/56812 | |
# date; for filename in *.json; do mv "${filename}" "${filename%.json}_${repo_name}.json"; done; date | |
# rename "s/\.json$/_${repo_name}.json/" *json | |
rename 'y/A-Z/a-z/' *json | |
sed -i "s|bucketsdir\\\\\\\\${repo_name}\\\\\\\\scripts|bucketsdir\\\\\\\\breathe\\\\\\\\scripts|g" *json | |
# copy bucket/scripts folder | |
cd "${TMP_DIR}/${repo_name}" | |
cp bucket ${TMP_DIR}/breathe/ -r -n | |
if [ -d "scripts" ]; then | |
cp scripts ${TMP_DIR}/breathe/ -r -n | |
fi | |
done | |
# copy bin folder to breathe | |
cp ${TMP_DIR}/main/bin ${TMP_DIR}/breathe/ -r -n | |
# replace head | |
sed -i "/${head_start}/,/${head_end}/{//!d;}" "${TMP_DIR}/breathe/README.md" | |
echo -e "${manifest_badge}" >"${TMP_DIR}/head.md" | |
sed -i "/${head_start}/r ${TMP_DIR}/head.md" "${TMP_DIR}/breathe/README.md" | |
} | |
# commit and push | |
function commit() { | |
# remove cracked | |
cd "${TMP_DIR}/breathe/bucket" | |
# grep -l "pan.jiemi.workers.dev" *.json | xargs -I {} rm {} | |
# push | |
cd "${TMP_DIR}/breathe" | |
if [ "$(git status -sb)" == "## main...origin/main" ];then | |
echo -e "\033[42;30m nothing to commit, working tree clean~ \033[0m" | |
else | |
git status -s && git pull origin main && git add . && git commit -m "Update by: ${USER}, at: ${DATE}" && git push origin main | |
fi | |
} | |
# sync to jihulab | |
function sync() { | |
git config --global user.name "Ryanjie" | |
git config --global user.email "4646-Ryanjie@users.noreply.test50k.gitlab.cn" | |
git config --global core.sshCommand "/usr/bin/ssh -i ~/.ssh/id_rsa" | |
git clone -q --depth=1 git@jihulab.com:Ryanjie/Breathe.git "${TMP_DIR}/breathe-cn" | |
cd ${TMP_DIR}/breathe/bucket/ | |
# sed -i 's|\(https://github.com/.*/releases/download\)|https://ghproxy.com/\1|g;s|\(https://github.com/.*/archive\)|https://ghproxy.com/\1|g;s|\(https://raw.githubusercontent.com/\)|https://ghproxy.com/\1|g' *json | |
cd ${TMP_DIR}/breathe-cn/ | |
if [ -d "bucket" ]; then | |
rm -rf bin bucket scripts | |
fi | |
mkdir bin bucket scripts | |
cp ${TMP_DIR}/breathe/bin ${TMP_DIR}/breathe-cn/ -r -n | |
cp ${TMP_DIR}/breathe/bucket ${TMP_DIR}/breathe-cn/ -r -n | |
cp ${TMP_DIR}/breathe/scripts ${TMP_DIR}/breathe-cn/ -r -n | |
cp ${TMP_DIR}/breathe/README.md ${TMP_DIR}/breathe-cn -r -n | |
if [ "$(git status -sb)" == "## main...origin/main" ];then | |
echo -e "\033[42;30m nothing to commit, working tree clean~ \033[0m" | |
else | |
git status -s && git pull origin main && git add . && git commit -m "Sync by: ${USER}, at: ${DATE}" && git push origin main | |
fi | |
} | |
init | |
build | |
commit | |
sync | |
- name: Remove ssh private key | |
run: rm -f ~/.ssh/id_rsa |