Skip to content

Commit 3a2cd81

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

File tree

3 files changed

+104
-66
lines changed

3 files changed

+104
-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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Read current package version
20+
id: read_version
21+
run: |
22+
# Use node to print the version only, capture it safely into a shell var and write to GITHUB_OUTPUT
23+
ver=$(node -e "process.stdout.write(require('./package.json').version)")
24+
echo "PACKAGE_VERSION=$ver" >> $GITHUB_OUTPUT
25+
26+
- name: "Debug: show package version"
27+
run: |
28+
echo "Read package version: ${{ steps.read_version.outputs.PACKAGE_VERSION }}"
29+
30+
- name: Configure git
31+
run: |
32+
git config user.name "github-actions[bot]"
33+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
34+
35+
- name: Fetch gh-pages branch
36+
run: |
37+
git fetch origin gh-pages:gh-pages || git checkout --orphan gh-pages
38+
39+
- name: Switch to gh-pages
40+
run: |
41+
git checkout gh-pages || git checkout --orphan gh-pages
42+
43+
- name: Update dependency version in gh-pages package.json
44+
shell: bash
45+
run: |
46+
echo "Updating or creating package.json with emoji-picker-react@${{ steps.read_version.outputs.PACKAGE_VERSION }}"
47+
PACKAGE_VERSION='${{ steps.read_version.outputs.PACKAGE_VERSION }}' node .github/scripts/update-gh-pages-package.js
48+
49+
- name: Install dependencies
50+
run: npm ci --legacy-peer-deps || npm install --no-audit --no-fund
51+
52+
- name: Commit version bump
53+
run: |
54+
git add package.json || true
55+
if git diff --staged --quiet; then
56+
echo "No changes to commit"
57+
else
58+
git commit -m "chore(gh-pages): update emoji-picker-react to ${{ steps.read_version.outputs.PACKAGE_VERSION }}"
59+
fi
60+
61+
- name: Push gh-pages
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
run: |
65+
git push origin gh-pages

.github/workflows/nextjs.yml

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

0 commit comments

Comments
 (0)