Skip to content

Commit d4f51a4

Browse files
authored
ci: restore old publish workflow (#49)
1 parent f9fc02c commit d4f51a4

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

.github/workflows/publish.yml

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
name: Publish
2-
3-
# Allow to run this workflow manually from the Actions tab
42
on:
5-
workflow_dispatch:
6-
inputs:
7-
package:
8-
description: 'Package to publish'
9-
type: string
10-
required: true
11-
default: 'mikel'
3+
push:
4+
tags: ['*']
5+
126
## Set permissions to the github token
137
## https://github.com/softprops/action-gh-release#permissions
148
permissions:
@@ -24,13 +18,22 @@ jobs:
2418
with:
2519
node-version: 20
2620
registry-url: 'https://registry.npmjs.org'
27-
- name: Publish primary package
28-
run: npm publish
29-
if: ${{ inputs.package == 'mikel' }}
21+
- run: npm publish
3022
env:
3123
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
32-
- name: Publish secondary package
33-
run: cd packages/${{ inputs.package }} && npm publish
34-
if: ${{ inputs.package != 'mikel' }}
24+
publish-packages:
25+
if: ${{ github.repository == 'jmjuanes/mikel' }}
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
package: [mikel-webpack-plugin, mikel-press, mikel-press-cli]
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: actions/setup-node@v4
33+
with:
34+
node-version: 20
35+
registry-url: 'https://registry.npmjs.org'
36+
- run: yarn release
37+
- run: cd packages/${{ matrix.package }} && npm publish
3538
env:
3639
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"./package.json": "./package.json"
1919
},
2020
"scripts": {
21+
"release": "node ./scripts/release.js",
2122
"test": "node test.js"
2223
},
2324
"keywords": [

scripts/release.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as fs from "node:fs";
2+
import * as path from "node:path";
3+
4+
// tiny helper to read and write a JSON file
5+
const readJson = file => {
6+
return JSON.parse(fs.readFileSync(file, "utf8"));
7+
};
8+
const writeJson = (file, data) => {
9+
return fs.writeFileSync(file, JSON.stringify(data, null, " "), "utf8");
10+
};
11+
12+
// read the package.json
13+
const pkg = readJson(path.join(process.cwd(), "package.json"));
14+
15+
// Fix the version in each package.json of the packages folder
16+
const packagesDir = path.join(process.cwd(), "packages");
17+
fs.readdirSync(packagesDir).forEach(dir => {
18+
const packageFile = path.join(packagesDir, dir, "package.json");
19+
const packageContent = readJson(packageFile);
20+
// 1. change version in package.json
21+
packageContent.version = pkg.version;
22+
// 2. change version in dependencies, devDependencies, and peerDependencies
23+
["dependencies", "devDependencies", "peerDependencies"].forEach(type => {
24+
Object.keys(packageContent[type] || {}).forEach(dep => {
25+
if (dep.startsWith("mikel")) {
26+
packageContent[type][dep] = "^" + pkg.version;
27+
}
28+
});
29+
});
30+
// 3. write the new package.json
31+
writeJson(packageFile, packageContent);
32+
});

0 commit comments

Comments
 (0)