|
| 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: Clone repo into /tmp and prepare gh-pages |
| 39 | + shell: bash |
| 40 | + env: |
| 41 | + REPO_URL: "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" |
| 42 | + run: | |
| 43 | + set -euo pipefail |
| 44 | + rm -rf /tmp/ghpages || true |
| 45 | + git clone "$REPO_URL" /tmp/ghpages |
| 46 | + cd /tmp/ghpages |
| 47 | + git fetch --all |
| 48 | + if git ls-remote --exit-code origin gh-pages; then |
| 49 | + git checkout gh-pages |
| 50 | + else |
| 51 | + git checkout --orphan gh-pages |
| 52 | + git rm -rf . || true |
| 53 | + git commit --allow-empty -m "chore(gh-pages): create gh-pages branch" || true |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Ensure helper script present and update package.json in clone |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + set -euo pipefail |
| 60 | + cd /tmp/ghpages |
| 61 | + mkdir -p .github/scripts |
| 62 | + if [ ! -f .github/scripts/update-gh-pages-package.js ]; then |
| 63 | + # Try to copy the script from origin/master (it may only exist on source branch) |
| 64 | + if git show origin/master:.github/scripts/update-gh-pages-package.js >/dev/null 2>&1; then |
| 65 | + git show origin/master:.github/scripts/update-gh-pages-package.js > .github/scripts/update-gh-pages-package.js |
| 66 | + git add .github/scripts/update-gh-pages-package.js |
| 67 | + fi |
| 68 | + fi |
| 69 | + if [ ! -f .github/scripts/update-gh-pages-package.js ]; then |
| 70 | + echo "Helper script not available in clone; cannot update package.json" >&2 |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + node .github/scripts/update-gh-pages-package.js "${{ steps.read_version.outputs.PACKAGE_VERSION }}" |
| 74 | +
|
| 75 | + - name: Install dependencies in clone |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | + cd /tmp/ghpages |
| 80 | + npm ci --legacy-peer-deps || npm install --no-audit --no-fund |
| 81 | +
|
| 82 | + - name: Commit and push gh-pages changes from clone |
| 83 | + shell: bash |
| 84 | + env: |
| 85 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | + cd /tmp/ghpages |
| 89 | + git add package.json || true |
| 90 | + if git diff --staged --quiet; then |
| 91 | + echo "No changes to commit" |
| 92 | + else |
| 93 | + git commit -m "chore(gh-pages): update emoji-picker-react to ${{ steps.read_version.outputs.PACKAGE_VERSION }}" |
| 94 | + git push origin gh-pages |
| 95 | + fi |
0 commit comments