Skip to content

Commit 5de3f70

Browse files
kkafararthwood
andauthored
chore(CI): add nightly publish workflow (#2890)
## Description Original PR: #2887 See it for description. ## Changes WIP ## Test code and steps to reproduce WIP ## Checklist - [ ] Ensured that CI passes --------- Co-authored-by: Artur Bilski <[email protected]>
1 parent a79b524 commit 5de3f70

7 files changed

Lines changed: 215 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
# Eliminate those annoying annotations from GitHub Actions
3+
echo "::remove-matcher owner=eslint-compact::"
4+
echo "::remove-matcher owner=eslint-stylish::"
5+
echo "::remove-matcher owner=tsc::"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build nightly and publish on npm
2+
env:
3+
YARN_ENABLE_HARDENED_MODE: 0
4+
on:
5+
schedule:
6+
- cron: '27 23 * * *' # at 23:27 every day
7+
workflow_dispatch:
8+
jobs:
9+
npm-build:
10+
if: github.repository == 'software-mansion/react-native-screens'
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
env:
16+
PACKAGE_NAME: PLACEHOLDER # Will be reassigned later on.
17+
steps:
18+
- name: Check out
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 22
25+
cache: 'yarn'
26+
registry-url: https://registry.npmjs.org/
27+
28+
- name: Clear annotations
29+
run: .github/workflows/helper/clear-annotations.sh
30+
31+
- name: Install node dependencies
32+
run: yarn install --immutable
33+
34+
- name: Build package
35+
id: build
36+
run: ./scripts/create-npm-package.sh
37+
38+
- name: Check if any node_modules were packed
39+
id: node_modules
40+
run: ! grep --silent -E "node_modules/.+" build.log
41+
42+
- name: Show build log
43+
if: failure() && steps.build.outcome == 'failure'
44+
run: cat build.log
45+
46+
- name: Show packed node_modules
47+
if: failure() && steps.node_modules.outcome == 'failure'
48+
run: ! grep -E "node_modules/.+" build.log
49+
50+
- name: Add package name to env
51+
run: echo "PACKAGE_NAME=$(ls -l | egrep -o "react-native-screens-(.*)(=?\.tgz)")" >> $GITHUB_ENV
52+
53+
- name: Assert PACKAGE_NAME
54+
if: ${{ env.PACKAGE_NAME == 'PLACEHOLDER' }}
55+
run: exit 1 # This should never happen.
56+
57+
- name: Upload npm package to GitHub
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: ${{ env.PACKAGE_NAME }}
61+
path: './${{ env.PACKAGE_NAME }}'
62+
63+
- name: Publish npm package
64+
run: npm publish $PACKAGE_NAME --tag nightly --provenance
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"@types/jest": "^29.5.13",
9292
"@types/react": "^19.0.0",
9393
"@types/react-test-renderer": "^19.0.0",
94+
"@types/shelljs": "^0",
9495
"@typescript-eslint/eslint-plugin": "^6.5.0",
9596
"@typescript-eslint/parser": "^6.5.0",
9697
"clang-format": "^1.8.0",
@@ -116,6 +117,7 @@
116117
"react-native-windows": "^0.64.8",
117118
"react-test-renderer": "^19.0.0",
118119
"release-it": "^15.6.0",
120+
"shelljs": "^0.9.2",
119121
"typescript": "5.4.3"
120122
},
121123
"resolutions": {

scripts/create-npm-package.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
yarn install --immutable
4+
5+
if ! CURRENT_VERSION=$(node ./set-version.js --nightly); then
6+
exit 1
7+
fi
8+
9+
yarn prepare
10+
11+
npm pack
12+
13+
node ./set-version.js "$CURRENT_VERSION" >/dev/null
14+
15+
echo "Done!"

scripts/releasing.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const { cat, exec } = require('shelljs');
2+
3+
/**
4+
* @param {string[]} args
5+
* @param {string} packageJsonPath
6+
* @returns {{ currentVersion: string; newVersion: string }}
7+
*/
8+
function getVersion(args, packageJsonPath) {
9+
let IS_NIGHTLY = false;
10+
let IS_SET_CUSTOM = false;
11+
12+
let customVersion = '';
13+
14+
args.slice(2).forEach(arg => {
15+
if (arg === '--nightly' || arg === '-n') {
16+
IS_NIGHTLY = true;
17+
} else {
18+
customVersion = arg;
19+
IS_SET_CUSTOM = true;
20+
}
21+
});
22+
23+
if (IS_NIGHTLY && IS_SET_CUSTOM) {
24+
throw new Error('Cannot set nightly or fresh version with custom version.');
25+
}
26+
27+
if (!IS_SET_CUSTOM && !IS_NIGHTLY) {
28+
throw new Error('Version not set.');
29+
}
30+
31+
const packageJson = JSON.parse(cat(packageJsonPath));
32+
const currentVersion = packageJson.version;
33+
34+
let newVersion = currentVersion;
35+
if (IS_SET_CUSTOM) {
36+
newVersion = customVersion;
37+
} else {
38+
if (currentVersion.includes('nightly')) {
39+
throw new Error('Cannot set nightly version on a nightly version');
40+
}
41+
42+
const dateIdentifier = new Date()
43+
.toISOString()
44+
.slice(0, -5)
45+
.replace(/[-:T]/g, '')
46+
.slice(0, -6);
47+
48+
const currentCommit = exec('git rev-parse HEAD', {
49+
silent: true,
50+
}).stdout.trim();
51+
const shortCommit = currentCommit.slice(0, 9);
52+
53+
newVersion = `${
54+
currentVersion.split('-')[0]
55+
}-nightly-${dateIdentifier}-${shortCommit}`;
56+
}
57+
58+
return {
59+
currentVersion,
60+
newVersion,
61+
};
62+
}
63+
64+
module.exports = {
65+
getVersion,
66+
};

scripts/set-version.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { getVersion } = require('./releasing');
4+
5+
const packageJsonPath = path.resolve(__dirname, '../package.json');
6+
7+
const { currentVersion, newVersion } = getVersion(
8+
process.argv,
9+
packageJsonPath
10+
);
11+
12+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
13+
packageJson.version = newVersion;
14+
const newPackageJson = JSON.stringify(packageJson, null, 2) + '\n';
15+
fs.writeFileSync(packageJsonPath, newPackageJson, 'utf-8');
16+
17+
// Log the current version so it can be restored if needed.
18+
console.log(currentVersion);

yarn.lock

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3527,6 +3527,16 @@ __metadata:
35273527
languageName: node
35283528
linkType: hard
35293529

3530+
"@types/glob@npm:~7.2.0":
3531+
version: 7.2.0
3532+
resolution: "@types/glob@npm:7.2.0"
3533+
dependencies:
3534+
"@types/minimatch": "npm:*"
3535+
"@types/node": "npm:*"
3536+
checksum: 10c0/a8eb5d5cb5c48fc58c7ca3ff1e1ddf771ee07ca5043da6e4871e6757b4472e2e73b4cfef2644c38983174a4bc728c73f8da02845c28a1212f98cabd293ecae98
3537+
languageName: node
3538+
linkType: hard
3539+
35303540
"@types/graceful-fs@npm:^4.1.2":
35313541
version: 4.1.9
35323542
resolution: "@types/graceful-fs@npm:4.1.9"
@@ -3608,6 +3618,13 @@ __metadata:
36083618
languageName: node
36093619
linkType: hard
36103620

3621+
"@types/minimatch@npm:*":
3622+
version: 5.1.2
3623+
resolution: "@types/minimatch@npm:5.1.2"
3624+
checksum: 10c0/83cf1c11748891b714e129de0585af4c55dd4c2cafb1f1d5233d79246e5e1e19d1b5ad9e8db449667b3ffa2b6c80125c429dbee1054e9efb45758dbc4e118562
3625+
languageName: node
3626+
linkType: hard
3627+
36113628
"@types/node-forge@npm:^1.3.0":
36123629
version: 1.3.11
36133630
resolution: "@types/node-forge@npm:1.3.11"
@@ -3666,6 +3683,16 @@ __metadata:
36663683
languageName: node
36673684
linkType: hard
36683685

3686+
"@types/shelljs@npm:^0":
3687+
version: 0.8.15
3688+
resolution: "@types/shelljs@npm:0.8.15"
3689+
dependencies:
3690+
"@types/glob": "npm:~7.2.0"
3691+
"@types/node": "npm:*"
3692+
checksum: 10c0/8cee3c2cee993d4e4b534712dbf3b47000f22e14cbc4fff5c09fd774272e2bfb9b7dfc654d81349a11ade93a94f3a75771e403cd31509565102c33f518185da8
3693+
languageName: node
3694+
linkType: hard
3695+
36693696
"@types/stack-utils@npm:^2.0.0":
36703697
version: 2.0.3
36713698
resolution: "@types/stack-utils@npm:2.0.3"
@@ -12888,6 +12915,7 @@ __metadata:
1288812915
"@types/jest": "npm:^29.5.13"
1288912916
"@types/react": "npm:^19.0.0"
1289012917
"@types/react-test-renderer": "npm:^19.0.0"
12918+
"@types/shelljs": "npm:^0"
1289112919
"@typescript-eslint/eslint-plugin": "npm:^6.5.0"
1289212920
"@typescript-eslint/parser": "npm:^6.5.0"
1289312921
clang-format: "npm:^1.8.0"
@@ -12915,6 +12943,7 @@ __metadata:
1291512943
react-native-windows: "npm:^0.64.8"
1291612944
react-test-renderer: "npm:^19.0.0"
1291712945
release-it: "npm:^15.6.0"
12946+
shelljs: "npm:^0.9.2"
1291812947
typescript: "npm:5.4.3"
1291912948
warn-once: "npm:^0.1.0"
1292012949
peerDependencies:
@@ -13962,6 +13991,20 @@ __metadata:
1396213991
languageName: node
1396313992
linkType: hard
1396413993

13994+
"shelljs@npm:^0.9.2":
13995+
version: 0.9.2
13996+
resolution: "shelljs@npm:0.9.2"
13997+
dependencies:
13998+
execa: "npm:^1.0.0"
13999+
fast-glob: "npm:^3.3.2"
14000+
interpret: "npm:^1.0.0"
14001+
rechoir: "npm:^0.6.2"
14002+
bin:
14003+
shjs: bin/shjs
14004+
checksum: 10c0/2aed1e2ff344b03a36aa018326ab768e4af88e22b0f3d89fbb2f15bca1a6cf6209c6d523658ebc7fc7986675ea75c7bdbce0501201b8883f1db21b22a50d5e6d
14005+
languageName: node
14006+
linkType: hard
14007+
1396514008
"shimmer@npm:^1.1.0, shimmer@npm:^1.2.0":
1396614009
version: 1.2.1
1396714010
resolution: "shimmer@npm:1.2.1"

0 commit comments

Comments
 (0)