study-area-cn/.gitea/workflows/build.yaml

141 lines
5.5 KiB
YAML
Raw Normal View History

2024-05-16 21:19:30 +08:00
name: Build and Publish
run-name: Build and Publish book (${{ gitea.actor }})
2024-05-18 12:52:31 +08:00
on: [push]
jobs:
2024-07-09 21:24:27 +08:00
Build:
runs-on: ubuntu-latest
steps:
- name: Info
run: echo "OS=${{ runner.os }} NAME=${{ gitea.event_name }} REPO=${{ gitea.repository }} BRANCH=${{ gitea.ref }} ST=${{ job.status }} RUNID=${{ gitea.run_id }}"
- name: Checkout
uses: https://git.hmtsai.cn/actions/checkout@v4
2024-07-08 22:18:45 +08:00
- name: Get Hash
id: src_hash
2024-07-08 22:27:00 +08:00
run: echo "::set-output name=src_hash::$(if [[ $(find src -type f -exec sha256sum {} \; | sha256sum | cut -d ' ' -f 1) = $(cat hash.txt) ]]; then echo run; else echo next; fi)"
- name: Cache Node
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' }}
uses: https://git.hmtsai.cn/actions/cache@v4
id: cache-node
env:
cache-name: cache-node
with:
key: ${{ runner.os }}-node
path: |
/node
- name: Prepare node
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' && steps.cache-node.outputs.cache-hit != 'true' }}
run: |
git clone https://git.hmtsai.cn/cxykevin/study-area-home-action-deps
mv study-area-home-action-deps/node-$(uname -m).tar.xz study-area-home-action-deps/node.tar.xz
tar xvJf study-area-home-action-deps/node.tar.xz
mv node-*-linux-* /node
export PATH=/node/bin:$PATH
echo $PATH
- name: Get npm root
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' }}
id: npm_root
run: echo "::set-output name=npmroot::$(npm root -g)"
- name: Cache Node Moudles
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' }}
id: cache-node-moudles
uses: https://git.hmtsai.cn/actions/cache@v4
env:
cache-name: cache-node-moudles
with:
key: ${{ runner.os }}-node_moudles
path: |
${{ steps.npm_root.outputs.npmroot }}
- name: Check node
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' }}
run: |
node -v
npm -v
- name: Prepare NPM source
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' }}
run: |
export PATH=/node/bin:$PATH
npm config set registry https://registry.npmmirror.com
- name: npm install
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' && steps.cache-node-moudles.outputs.cache-hit != 'true' }}
run: |
export PATH=/node/bin:$PATH
npm install -g @lint-md/cli
- name: Format
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' }}
run: |
export PATH=/node/bin:$PATH
lint-md src/**/* --threads=8 --fix --suppress-warnings
2024-07-08 22:18:45 +08:00
- name: Set hash cache
if: ${{ steps.src_hash.outputs.src_hash != 'run' }}
run: |
echo "$(find src -type f -exec sha256sum {} \; | sha256sum | cut -d ' ' -f 1)" > hash.txt
- name: Commit files
2024-07-08 22:18:45 +08:00
if: ${{ steps.src_hash.outputs.src_hash != 'run' }}
run: |
git config --global user.name "studyareacn-format-bot"
git config --global user.email "studyareacn-format@noreply.localhost"
git remote set-url origin https://${{ secrets.GIT_USER }}:${{ secrets.GIT_PASSWD }}@git.hmtsai.cn/study-area-cn/study-area-cn
git add .
git commit -m "Auto format"
2024-07-09 21:17:39 +08:00
echo "__import__(\"os\").system(\"sh -c \\\"git push\\\"\")" > ezpush.py && python3 ezpush.py
2024-07-09 21:28:11 +08:00
- name: "-------------"
2024-07-08 22:18:45 +08:00
id: src_hash
2024-07-09 21:28:11 +08:00
run: echo "-------------"
- name: Prepare Source
run: |
echo "--- write source ---"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free">/etc/apt/sources.list
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free">>/etc/apt/sources.list
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free">>/etc/apt/sources.list
cat /etc/apt/sources.list
rm -rf /etc/apt/sources.list.d/*
echo "--- update source ---"
apt-get update
- name: Prepare Lftp
run: |
apt-get install lftp -y
2024-05-26 06:59:04 +08:00
- name: Cache mdbook
uses: https://git.hmtsai.cn/actions/cache@v4
id: cache-mdbook
env:
cache-name: cache-mdbook
with:
key: ${{ runner.os }}-mdbook
path: |
study-area-action-deps
- name: Get file
2024-07-09 21:28:11 +08:00
if: ${{ steps.cache-mdbook.outputs.cache-hit != 'true' }}
run: |
2024-05-23 11:58:01 +08:00
git clone https://git.hmtsai.cn/cxykevin/study-area-action-deps
echo "Check..."
ls study-area-action-deps
- name: Add permission
2024-05-19 09:54:14 +08:00
run: chmod +x study-area-action-deps/mdbook-linux-$(uname -m)
- name: Build mdbook
2024-05-19 09:53:25 +08:00
run: study-area-action-deps/mdbook-linux-$(uname -m) build
2024-06-29 19:27:04 +08:00
- name: Cache mapbook
uses: https://git.hmtsai.cn/actions/cache@v4
id: cache-mapbook
env:
cache-name: cache-mapbook
with:
key: mapbook
path: |
mapbook
- name: Get mapbook
2024-07-09 21:28:11 +08:00
if: ${{ steps.cache-mapbook.outputs.cache-hit != 'true' }}
2024-06-29 19:27:04 +08:00
run: |
git clone https://git.hmtsai.cn/cxykevin/mapbook
echo "Check..."
ls mapbook
- name: Build sitemap
run: |
2024-06-29 19:31:18 +08:00
python3 mapbook/build.py
- name: Check book
run: ls book
- name: Upload
2024-06-25 22:37:00 +08:00
run: |
mv book index
lftp ${{ secrets.FTP_SITE }} -u ${{ secrets.FTP_USERNAME }},${{ secrets.FTP_PWD }} -e "mirror -R index index"