Download dan Save Module #151
This file contains hidden or 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: Download dan Save Module | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
push: | |
branches: | |
- main | |
jobs: | |
Module: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
lfs: true | |
- name: Setup Git LFS | |
run: | | |
git lfs install | |
echo "modules_storage/** filter=lfs diff=lfs merge=lfs -text" > .gitattributes | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
run: | | |
# Initialize npm if package.json doesn't exist | |
if [ ! -f package.json ]; then | |
npm init -y | |
fi | |
# Install modules and ensure `node_modules` is created | |
npm install chart.js @tensorflow/tfjs-node @angular/cli @polymer/polymer react react-dom shadcn/ui tailwindcss @webcomponents/custom-elements express cors helmet compression mongoose firebase-admin bcryptjs --save | |
# Create `modules_storage` directory | |
mkdir -p modules_storage | |
# Copy scoped modules | |
for dir in node_modules/@*/ ; do | |
if [ -d "$dir" ]; then | |
scope=$(basename $dir) | |
mkdir -p "modules_storage/$scope" | |
cp -r "$dir"* "modules_storage/$scope/" | |
fi | |
done | |
# Copy non-scoped modules | |
for dir in node_modules/[^@]*/ ; do | |
if [ -d "$dir" ]; then | |
module=$(basename $dir) | |
mkdir -p "modules_storage/$module" | |
cp -r "$dir"* "modules_storage/$module/" | |
fi | |
done | |
- name: Update package.json timestamp | |
run: | | |
CURRENT_DATE=$(date '+%Y-%m-%d') | |
jq --arg date "$CURRENT_DATE" '.lastUpdate = $date' package.json > temp.json && mv temp.json package.json | |
- name: Configure Git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Commit and Push Changes | |
run: | | |
git add .gitattributes | |
git add modules_storage/ | |
git add package.json | |
git add package-lock.json | |
git commit -m "Update modules - $(date +'%Y-%m-%d')" || true | |
git push origin main || true |