auto update gh-pages #6
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: Update gh-pages dependency and push | |
| on: | |
| push: | |
| branches: ["master", "main"] | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-gh-pages: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout current branch at workspace root | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| path: "." | |
| clean: true | |
| persist-credentials: true | |
| - name: Read current package version | |
| id: read_version | |
| run: | | |
| # Use node to print the version only, capture it safely into a shell var and write to GITHUB_OUTPUT | |
| ver=$(node -e "process.stdout.write(require('./package.json').version)") | |
| echo "PACKAGE_VERSION=$ver" >> $GITHUB_OUTPUT | |
| - name: "Debug: show package version" | |
| run: | | |
| echo "Read package version: ${{ steps.read_version.outputs.PACKAGE_VERSION }}" | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Fetch gh-pages branch | |
| run: | | |
| git fetch origin gh-pages:gh-pages || git checkout --orphan gh-pages | |
| - name: Switch to gh-pages | |
| run: | | |
| git checkout gh-pages || git checkout --orphan gh-pages | |
| - name: Update dependency version in gh-pages package.json | |
| shell: bash | |
| run: | | |
| echo "Updating or creating package.json with emoji-picker-react@${{ steps.read_version.outputs.PACKAGE_VERSION }}" | |
| echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE" | |
| ls -la "$GITHUB_WORKSPACE/.github/scripts" || true | |
| # Try several candidate locations for the helper script to handle nested checkout layouts | |
| CANDIDATES=( | |
| "$GITHUB_WORKSPACE/.github/scripts/update-gh-pages-package.js" | |
| "$GITHUB_WORKSPACE/../.github/scripts/update-gh-pages-package.js" | |
| "$GITHUB_WORKSPACE/$GITHUB_REPOSITORY/.github/scripts/update-gh-pages-package.js" | |
| ) | |
| SCRIPT_PATH="" | |
| for p in "${CANDIDATES[@]}"; do | |
| if [ -f "$p" ]; then | |
| SCRIPT_PATH="$p" | |
| break | |
| fi | |
| done | |
| if [ -z "$SCRIPT_PATH" ]; then | |
| echo "Helper script not found in candidates:" >&2 | |
| for c in "${CANDIDATES[@]}"; do echo " $c" >&2; done | |
| # As a last resort, try a find under the runner work dir (may be slow) | |
| echo "Searching /home/runner/work for update-gh-pages-package.js (this may take a moment)" | |
| SCRIPT_PATH=$(find /home/runner/work -maxdepth 4 -name update-gh-pages-package.js -print -quit || true) | |
| fi | |
| echo "Using script: $SCRIPT_PATH" | |
| if [ -z "$SCRIPT_PATH" ]; then | |
| echo "Error: could not locate update-gh-pages-package.js" >&2 | |
| exit 1 | |
| fi | |
| node "$SCRIPT_PATH" "${{ steps.read_version.outputs.PACKAGE_VERSION }}" | |
| - name: Install dependencies | |
| run: npm ci --legacy-peer-deps || npm install --no-audit --no-fund | |
| - name: Commit version bump | |
| run: | | |
| git add package.json || true | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "chore(gh-pages): update emoji-picker-react to ${{ steps.read_version.outputs.PACKAGE_VERSION }}" | |
| fi | |
| - name: Push gh-pages | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git push origin gh-pages |