Skip to content

lcsc as number

lcsc as number #1195

name: "Update component database"
on:
push:
pull_request:
schedule:
- cron: '0 3 * * *'
jobs:
build_and_update:
name: "Update component database and frontend"
runs-on: ubuntu-22.04
environment: github-pages
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
python3 python3-pip nodejs npm wget zip unzip p7zip-full
sudo pip3 install requests click
- name: Build frontend
run: |
cd web
if [ "$GITHUB_REPOSITORY" = 'yaqwsx/jlcparts-dev' ]; then
export BASEURL=https://jlcparts-dev.honzamrazek.cz
else
export BASEURL=https://yaqwsx.github.io/jlcparts
fi
npm install --silent
NODE_ENV=production PUBLIC_URL=${BASEURL} npm run build
if [ $GITHUB_REPOSITORY = 'yaqwsx/jlcparts-dev' ]; then
echo 'jlcparts-dev.honzamrazek.cz' > build/CNAME
fi
touch .nojekyll
- name: Update database
env: # Or as an environment variable
LCSC_KEY: ${{ secrets.LCSC_KEY }}
LCSC_SECRET: ${{ secrets.LCSC_SECRET }}
JLCPCB_KEY: ${{ secrets.JLCPCB_KEY }}
JLCPCB_SECRET: ${{ secrets.JLCPCB_SECRET }}
run: |
set -x
sudo pip3 install -e .
wget -q https://yaqwsx.github.io/jlcparts/data/cache.zip
for seq in $(seq 1 9); do
wget -q https://yaqwsx.github.io/jlcparts/data/cache.z0$seq || true
done
7z x cache.zip
jlcparts fetchtable parts.csv
jlcparts getlibrary --age 10000 \
--limit 15000 \
parts.csv cache.sqlite3
jlcparts updatepreferred cache.sqlite3
jlcparts buildtables --jobs 0 \
--ignoreoldstock 120 \
cache.sqlite3 web/build/data
rm -f web/build/data/cache.z*
zip -s 50m web/build/data/cache.zip cache.sqlite3
- name: Tar artifact # Artifact are case insensitive, this is workaround
run: tar -czf web_build.tar.gz web/build/
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: web_build
path: web_build.tar.gz
retention-days: 14
- name: Upload table
uses: actions/upload-artifact@v3
with:
name: component_table
path: parts.csv
retention-days: 14
deploy:
name: "Deploy"
runs-on: ubuntu-22.04
needs: build_and_update
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout # Required for GH-pages deployment
uses: actions/checkout@v3
- name: "Download web"
uses: actions/download-artifact@v3
with:
name: web_build
- name: Untar artifact
run: tar -xzf web_build.tar.gz
- name: Deploy to GH Pages
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: web/build
single-commit: true