0-update-clean-website-dependencies #93
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: 0-update-clean-website-dependencies | |
# Update and clean website dependencies | |
# Workflow triggered every week on Tuesday at 11:00 AM EST | |
# Can also be triggered manually without input parameters | |
on: | |
schedule: | |
- cron: '0 15 * * 2' # Every Tuesday at 11:00 AM EST | |
workflow_dispatch: | |
# Concurrency configuration for the current workflow - Keep only the latest workflow queued for the considered group | |
concurrency: | |
group: update-clean-website-dependencies | |
cancel-in-progress: true | |
jobs: | |
update-clean-website-dependencies: | |
runs-on: ubuntu-latest | |
env: | |
RUNNER_DEBUG: 1 | |
steps: | |
# Action used to checkout the main branch in the current repository | |
# Community action: https://github.com/actions/checkout | |
- name: Checkout | |
uses: actions/checkout@v4.1.1 | |
# Set a current date environment variable in the following format: YYYYMMDD | |
- name: Set current date as env variable | |
id: current_date | |
run: echo "NOW=$(date +'%Y%m%d')" >> $env:GITHUB_OUTPUT | |
shell: pwsh | |
# Setup Node.js | |
# Action: https://github.com/actions/setup-node | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
# Install dependencies and update dependencies | |
- name: Install dependencies and update dependencies | |
working-directory: Website | |
run: | | |
npm install -g npm-check-updates | |
npm ci | |
ncu -u | |
npm install | |
# Remove unused dependencies | |
- name: Remove unused dependencies | |
working-directory: Website | |
run: | | |
npm install -g depcheck | |
depcheck || true | |
unused=$(depcheck --json | jq -r '.dependencies[]') | |
if [ -z "$unused" ]; then | |
echo "No unused dependencies to uninstall" | |
else | |
for pkg in $unused; do echo "Uninstalling $pkg"; npm uninstall $pkg; done | |
fi | |
# Build the website | |
- name: Build website | |
working-directory: Website | |
run: | | |
npm run build | |
# Run unit tests | |
- name: Run unit tests | |
working-directory: Website | |
run: | | |
npm run test:unit | |
# Commit and push if it's necessary | |
- name: Commit and push if it's necessary | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
if git diff --quiet && git diff --staged --quiet; then | |
echo "No changes to commit" | |
else | |
git add . | |
git commit -m "Automated update of dependencies, removal of unused dependencies and tests - ${{ steps.current_date.outputs.NOW }}.${{ github.run_number }}" | |
git push | |
fi |