|
| 1 | +name: Update gh-pages dependency and push |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["master", "main"] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + update-gh-pages: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout current branch at workspace root |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + path: "." |
| 19 | + clean: true |
| 20 | + persist-credentials: true |
| 21 | + |
| 22 | + - name: Read current package version |
| 23 | + id: read_version |
| 24 | + run: | |
| 25 | + # Use node to print the version only, capture it safely into a shell var and write to GITHUB_OUTPUT |
| 26 | + ver=$(node -e "process.stdout.write(require('./package.json').version)") |
| 27 | + echo "PACKAGE_VERSION=$ver" >> $GITHUB_OUTPUT |
| 28 | +
|
| 29 | + - name: "Debug: show package version" |
| 30 | + run: | |
| 31 | + echo "Read package version: ${{ steps.read_version.outputs.PACKAGE_VERSION }}" |
| 32 | +
|
| 33 | + - name: Configure git |
| 34 | + run: | |
| 35 | + git config user.name "github-actions[bot]" |
| 36 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 37 | +
|
| 38 | + - name: Fetch gh-pages branch |
| 39 | + run: | |
| 40 | + git fetch origin gh-pages:gh-pages || git checkout --orphan gh-pages |
| 41 | +
|
| 42 | + - name: Switch to gh-pages |
| 43 | + run: | |
| 44 | + git checkout gh-pages || git checkout --orphan gh-pages |
| 45 | +
|
| 46 | + - name: Update dependency version in gh-pages package.json |
| 47 | + shell: bash |
| 48 | + run: | |
| 49 | + echo "Updating or creating package.json with emoji-picker-react@${{ steps.read_version.outputs.PACKAGE_VERSION }}" |
| 50 | + echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE" |
| 51 | + ls -la "$GITHUB_WORKSPACE/.github/scripts" || true |
| 52 | + # Try several candidate locations for the helper script to handle nested checkout layouts |
| 53 | + CANDIDATES=( |
| 54 | + "$GITHUB_WORKSPACE/.github/scripts/update-gh-pages-package.js" |
| 55 | + "$GITHUB_WORKSPACE/../.github/scripts/update-gh-pages-package.js" |
| 56 | + "$GITHUB_WORKSPACE/$GITHUB_REPOSITORY/.github/scripts/update-gh-pages-package.js" |
| 57 | + ) |
| 58 | + SCRIPT_PATH="" |
| 59 | + for p in "${CANDIDATES[@]}"; do |
| 60 | + if [ -f "$p" ]; then |
| 61 | + SCRIPT_PATH="$p" |
| 62 | + break |
| 63 | + fi |
| 64 | + done |
| 65 | + if [ -z "$SCRIPT_PATH" ]; then |
| 66 | + echo "Helper script not found in candidates:" >&2 |
| 67 | + for c in "${CANDIDATES[@]}"; do echo " $c" >&2; done |
| 68 | + # As a last resort, try a find under the runner work dir (may be slow) |
| 69 | + echo "Searching /home/runner/work for update-gh-pages-package.js (this may take a moment)" |
| 70 | + SCRIPT_PATH=$(find /home/runner/work -maxdepth 4 -name update-gh-pages-package.js -print -quit || true) |
| 71 | + fi |
| 72 | + echo "Using script: $SCRIPT_PATH" |
| 73 | + if [ -z "$SCRIPT_PATH" ]; then |
| 74 | + echo "Error: could not locate update-gh-pages-package.js" >&2 |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + node "$SCRIPT_PATH" "${{ steps.read_version.outputs.PACKAGE_VERSION }}" |
| 78 | +
|
| 79 | + - name: Install dependencies |
| 80 | + run: npm ci --legacy-peer-deps || npm install --no-audit --no-fund |
| 81 | + |
| 82 | + - name: Commit version bump |
| 83 | + run: | |
| 84 | + git add package.json || true |
| 85 | + if git diff --staged --quiet; then |
| 86 | + echo "No changes to commit" |
| 87 | + else |
| 88 | + git commit -m "chore(gh-pages): update emoji-picker-react to ${{ steps.read_version.outputs.PACKAGE_VERSION }}" |
| 89 | + fi |
| 90 | +
|
| 91 | + - name: Push gh-pages |
| 92 | + env: |
| 93 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + run: | |
| 95 | + git push origin gh-pages |
0 commit comments