Skip to content

ci: fix ci to not pull readme if not modification done + add generate… #25

ci: fix ci to not pull readme if not modification done + add generate…

ci: fix ci to not pull readme if not modification done + add generate… #25

Workflow file for this run

name: Deploy to GitHub Pages
on:
workflow_dispatch:
push:
branches:
- main
jobs:
prepare-plugin-data:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- name: Restore plugin release commit cache
id: cache-commit
uses: actions/cache/restore@v4
with:
path: .plugin-release-commit
key: plugin-release-commit-${{ github.sha }}
restore-keys: |
plugin-release-commit-
- name: Check and download plugin data
id: plugin-data
run: |
# Get the latest release commit SHA from the plugins repo
LATEST_COMMIT=$(curl -s https://api.github.com/repos/litestar-org/plugins/releases/latest | jq -r '.target_commitish')
echo "Latest release commit: $LATEST_COMMIT"
# Check if we have a cached commit
if [ -f .plugin-release-commit ]; then
CURRENT_COMMIT=$(cat .plugin-release-commit)
echo "Current cached commit: $CURRENT_COMMIT"
else
CURRENT_COMMIT=""
echo "No cached commit found"
fi
# Compare commits
if [ "$LATEST_COMMIT" = "$CURRENT_COMMIT" ] && [ -n "$CURRENT_COMMIT" ]; then
echo "Plugin data is up to date (commit: $LATEST_COMMIT)"
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "Plugin data needs update (current: $CURRENT_COMMIT, latest: $LATEST_COMMIT)"
echo "changed=true" >> $GITHUB_OUTPUT
echo "Downloading plugin data from latest release..."
curl -L -o plugins-data.zip \
https://github.com/litestar-org/plugins/releases/latest/download/plugins-and-readmes.zip
echo "Extracting plugin data..."
unzip -o plugins-data.zip
echo "Moving files to content directories..."
# Remove existing plugin files to ensure clean state
rm -rf content/plugins/*.yml content/readme/*.md
# Move extracted files to content directories
mv plugins/*.yml content/plugins/
mv readmes/*.md content/readme/
# Store the new commit for caching
echo "$LATEST_COMMIT" > .plugin-release-commit
# Clean up
rm -rf plugins readmes plugins-data.zip
echo "Plugin data updated successfully"
echo "Plugin count: $(ls -1 content/plugins/*.yml 2>/dev/null | wc -l)"
echo "README count: $(ls -1 content/readme/*.md 2>/dev/null | wc -l)"
fi
- name: Save plugin release commit cache
if: steps.plugin-data.outputs.changed == 'true'
uses: actions/cache/save@v4
with:
path: .plugin-release-commit
key: plugin-release-commit-${{ github.sha }}
- name: Commit and push plugin data
if: steps.plugin-data.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add content/plugins/*.yml content/readme/*.md
# Only commit if there are changes
if git diff --staged --quiet; then
echo "No changes to plugin data"
else
git commit -m "chore: update plugin data from latest release [skip ci]"
git push
echo "Plugin data committed and pushed to main"
fi
- name: Upload workspace
uses: actions/upload-artifact@v4
with:
name: workspace-with-plugins
path: .
build:
needs: prepare-plugin-data
runs-on: ubuntu-latest
steps:
- name: Download workspace
uses: actions/download-artifact@v4
with:
name: workspace-with-plugins
path: .
- run: corepack enable
- uses: actions/setup-node@v6
with:
node-version: '22'
# Pick your own package manager and build script
- run: pnpm install --frozen-lockfile
- name: Update stats
run: pnpm run update-stats
- run: pnpm run generate-github
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: ./.output/public
# Deployment job
deploy:
# Add a dependency to the build job
needs: build
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4