Skip to content

Commit e1e9bc5

Browse files
committed
auto update gh-pages
1 parent 94a4cfb commit e1e9bc5

File tree

3 files changed

+134
-66
lines changed

3 files changed

+134
-66
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
4+
// Accept version as first arg or from env
5+
const versionArg = process.argv[2] || process.env.PACKAGE_VERSION;
6+
if (!versionArg) {
7+
console.error('Usage: update-gh-pages-package.js <version>');
8+
process.exit(2);
9+
}
10+
11+
const version = versionArg;
12+
13+
function updatePackageJson() {
14+
const pkgPath = './package.json';
15+
if (fs.existsSync(pkgPath)) {
16+
const p = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
17+
if (!p.dependencies) p.dependencies = {};
18+
p.dependencies['emoji-picker-react'] = version;
19+
fs.writeFileSync(pkgPath, JSON.stringify(p, null, 2) + '\n');
20+
console.log(
21+
`Updated package.json dependency emoji-picker-react to ${version}`
22+
);
23+
} else {
24+
const p = {
25+
name: 'gh-pages',
26+
version: '0.0.0',
27+
dependencies: { 'emoji-picker-react': version },
28+
};
29+
fs.writeFileSync(pkgPath, JSON.stringify(p, null, 2) + '\n');
30+
console.log(`Created package.json with emoji-picker-react@${version}`);
31+
}
32+
}
33+
34+
try {
35+
updatePackageJson();
36+
} catch (err) {
37+
console.error('Failed to update package.json:', err);
38+
process.exit(1);
39+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

.github/workflows/nextjs.yml

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)