Skip to content

Commit 935d041

Browse files
committed
chore: Change CI
1 parent 53b2945 commit 935d041

File tree

4 files changed

+281
-211
lines changed

4 files changed

+281
-211
lines changed

.github/workflows/ci.yml

Lines changed: 161 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,184 @@ on:
44
push:
55
branches:
66
- master
7+
tags:
8+
- v*
79
pull_request:
810
branches:
911
- master
1012

1113
jobs:
12-
test:
13-
name: Native
14+
build-test:
1415
runs-on: ${{ matrix.os }}
1516
strategy:
17+
fail-fast: false
1618
matrix:
17-
os: [ubuntu-latest, macos-latest]
18-
node-version: [12.x]
19+
os: [ubuntu-latest, macos-latest, windows-latest]
1920
steps:
20-
- uses: actions/checkout@v1
21-
22-
- name: Use Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v1
21+
- uses: actions/checkout@v2
22+
- uses: actions/setup-node@v1
2423
with:
25-
node-version: ${{ matrix.node-version }}
26-
27-
- name: Cache esy dependencies
28-
uses: actions/cache@v1
29-
id: cache
30-
with:
31-
path: _export
32-
key: ${{ runner.OS }}-build-${{ hashFiles('esy.lock/index.json') }}
33-
restore-keys: |
34-
${{ runner.OS }}-build-${{ env.cache-name }}-
35-
${{ runner.OS }}-build-
36-
${{ runner.OS }}-
37-
24+
node-version: 12
3825
- name: Install esy
39-
run: npm install -g [email protected].6
26+
run: npm install -g [email protected].7
4027

41-
- name: Import dependencies
42-
if: steps.cache.outputs.cache-hit == 'true'
43-
run: esy import-build _export/*
28+
- name: Try to restore install cache
29+
uses: actions/cache@v2
30+
with:
31+
path: ~/.esy/source
32+
key: source-${{ matrix.os }}-${{ hashFiles('**/index.json') }}
4433

4534
- name: Install dependencies
4635
run: esy install
4736

48-
- name: Build
37+
- name: Print esy cache
38+
id: print_esy_cache
39+
run: node .github/workflows/print-esy-cache.js
40+
41+
- name: Try to restore dependencies cache
42+
id: deps-cache
43+
uses: actions/cache@v2
44+
with:
45+
path: ${{ steps.print_esy_cache.outputs.esy_cache }}
46+
key: build-${{ matrix.os }}-${{ hashFiles('**/index.json') }}
47+
restore-keys: build-${{ matrix.os }}-
48+
49+
- name: Build dependencies
50+
if: steps.deps-cache.outputs.cache-hit != 'true'
51+
run: esy build-dependencies
52+
53+
- name: Build project
4954
run: esy build
5055

51-
- name: Run tests
56+
- name: Run Native tests
5257
run: esy test
5358

54-
- name: Export dependencies
55-
run: esy export-dependencies
59+
- name: Create npm package
60+
run: esy npm-release
61+
- uses: actions/upload-artifact@v2
62+
with:
63+
name: ${{ matrix.os }}
64+
path: _release/
65+
66+
# Cleanup build cache if dependencies have changed
67+
- name: Clean build cache
68+
if: steps.deps-cache.outputs.cache-hit != 'true'
69+
run: esy cleanup .
70+
71+
prepare-publish:
72+
name: Prepare publish to npm
73+
needs: build-test
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/setup-node@v1
77+
with:
78+
node-version: 12
79+
- uses: actions/checkout@v2
80+
81+
# Download platform artifacts
82+
- name: Download Linux release
83+
uses: actions/download-artifact@v2
84+
with:
85+
name: ubuntu-latest
86+
path: ubuntu-latest
87+
- name: Download Windows release
88+
uses: actions/download-artifact@v2
89+
with:
90+
name: windows-latest
91+
path: windows-latest
92+
- name: Download macOS release
93+
uses: actions/download-artifact@v2
94+
with:
95+
name: macos-latest
96+
path: macos-latest
97+
# Move artifacts in place
98+
- name: Move artifacts
99+
run: |
100+
mkdir -p _release/platform-linux
101+
mkdir -p _release/platform-windows-x64
102+
mkdir -p _release/platform-darwin
103+
cp -a ubuntu-latest/. _release/platform-linux
104+
cp -a windows-latest/. _release/platform-windows-x64
105+
cp -a macos-latest/. _release/platform-darwin
106+
- name: Prepare package
107+
run: node .github/workflows/release.js
108+
# Create a npm package that can easily be published and tested
109+
- name: npm pack
110+
run: npm pack .
111+
working-directory: _release
112+
- name: move package
113+
run: mv _release/*.tgz react-rules-of-hooks-ppx.tgz
114+
# Upload artifacts
115+
- uses: actions/upload-artifact@v2
116+
with:
117+
name: release
118+
path: _release/
119+
- uses: actions/upload-artifact@v2
120+
with:
121+
name: release-tarball
122+
path: react-rules-of-hooks-ppx.tgz
123+
124+
publish:
125+
needs: prepare-publish
126+
name: (only on release) Publish
127+
runs-on: ubuntu-latest
128+
steps:
129+
- uses: actions/checkout@v2
130+
131+
- name: Use Node.js 12.x
132+
uses: actions/setup-node@v1
133+
with:
134+
node-version: 12.x
135+
136+
- name: Print short SHA
137+
id: sha
138+
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
139+
140+
- name: Download release
141+
uses: actions/download-artifact@v2
142+
with:
143+
name: release
144+
path: release
145+
146+
- name: Zip release folder
147+
run: zip -r release.zip release
148+
149+
- name: Create GitHub release
150+
id: create_release
151+
uses: actions/create-release@v1
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
154+
with:
155+
tag_name: ${{ github.ref }}
156+
release_name: Release ${{ github.ref }}
157+
draft: false
158+
prerelease: false
159+
160+
- name: Upload ubuntu-latest to Github release
161+
uses: actions/upload-release-asset@v1
162+
env:
163+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
164+
with:
165+
upload_url: ${{ steps.create_release.outputs.upload_url }}
166+
asset_path: release.zip
167+
asset_name: release.zip
168+
asset_content_type: application/gzip
169+
170+
- name: Release nightly NPM package
171+
if: github.event_name == 'pull_request'
172+
run: |
173+
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
174+
npm version prerelease --preid nightly.${{ steps.sha.outputs.sha_short }} -no-git-tag-version
175+
npm publish --access public --tag nightly
176+
working-directory: ./_release
177+
env:
178+
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
179+
180+
- name: Release NPM package
181+
if: "startsWith(github.ref, 'refs/tags/v')"
182+
run: |
183+
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
184+
npm publish --access public
185+
working-directory: ./_release
186+
env:
187+
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const fs = require("fs");
2+
const os = require("os");
3+
const path = require("path");
4+
5+
const ESY_FOLDER = process.env.ESY__PREFIX
6+
? process.env.ESY__PREFIX
7+
: path.join(os.homedir(), ".esy");
8+
const esy3 = fs
9+
.readdirSync(ESY_FOLDER)
10+
.filter((name) => name.length > 0 && name[0] === "3")
11+
.sort()
12+
.pop();
13+
console.log(`::set-output name=esy_cache::${path.join(ESY_FOLDER, esy3, "i")}`);

.github/workflows/release.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
console.log("Creating package.json");
5+
6+
// From the project root pwd
7+
const mainPackageJsonPath = fs.existsSync("esy.json")
8+
? "esy.json"
9+
: "package.json";
10+
11+
const exists = fs.existsSync(mainPackageJsonPath);
12+
13+
if (!exists) {
14+
console.error("No package.json or esy.json at " + mainPackageJsonPath);
15+
process.exit(1);
16+
}
17+
18+
// Now require from this script's location.
19+
const mainPackageJson = require(path.join("..", "..", mainPackageJsonPath));
20+
const bins = Array.isArray(mainPackageJson.esy.release.bin)
21+
? mainPackageJson.esy.release.bin.reduce(
22+
(acc, curr) => Object.assign({ [curr]: "bin/" + curr }, acc),
23+
{}
24+
)
25+
: Object.keys(mainPackageJson.esy.release.bin).reduce(
26+
(acc, currKey) =>
27+
Object.assign(
28+
{ [currKey]: "bin/" + mainPackageJson.esy.release.bin[currKey] },
29+
acc
30+
),
31+
{}
32+
);
33+
34+
const rewritePrefix =
35+
mainPackageJson.esy &&
36+
mainPackageJson.esy.release &&
37+
mainPackageJson.esy.release.rewritePrefix;
38+
39+
const packageJson = JSON.stringify(
40+
{
41+
...mainPackageJson,
42+
scripts: {
43+
postinstall: rewritePrefix
44+
? "ESY_RELEASE_REWRITE_PREFIX=true node ./postinstall.js"
45+
: "node ./postinstall.js",
46+
},
47+
bin: bins,
48+
files: [
49+
"_export/",
50+
"bin/",
51+
"postinstall.js",
52+
"esyInstallRelease.js",
53+
"platform-linux/",
54+
"platform-darwin/",
55+
"platform-windows-x64/",
56+
],
57+
},
58+
null,
59+
2
60+
);
61+
62+
fs.writeFileSync(
63+
path.join(__dirname, "..", "..", "_release", "package.json"),
64+
packageJson,
65+
{
66+
encoding: "utf8",
67+
}
68+
);
69+
70+
try {
71+
console.log("Copying LICENSE");
72+
fs.copyFileSync(
73+
path.join(__dirname, "..", "..", "LICENSE"),
74+
path.join(__dirname, "..", "..", "_release", "LICENSE")
75+
);
76+
} catch (e) {
77+
console.warn("No LICENSE found");
78+
}
79+
80+
console.log("Copying README.md");
81+
fs.copyFileSync(
82+
path.join(__dirname, "..", "..", "README.md"),
83+
path.join(__dirname, "..", "..", "_release", "README.md")
84+
);
85+
86+
console.log("Copying postinstall.js");
87+
fs.copyFileSync(
88+
path.join(__dirname, "release-postinstall.js"),
89+
path.join(__dirname, "..", "..", "_release", "postinstall.js")
90+
);
91+
92+
console.log("Creating placeholder files");
93+
const placeholderFile = `:; echo "You need to have postinstall enabled"; exit $?
94+
@ECHO OFF
95+
ECHO You need to have postinstall enabled`;
96+
fs.mkdirSync(path.join(__dirname, "..", "..", "_release", "bin"));
97+
98+
Object.keys(bins).forEach((name) => {
99+
if (bins[name]) {
100+
const binPath = path.join(__dirname, "..", "..", "_release", bins[name]);
101+
fs.writeFileSync(binPath, placeholderFile);
102+
fs.chmodSync(binPath, 0777);
103+
} else {
104+
console.log("bins[name] name=" + name + " was empty. Weird.");
105+
console.log(bins);
106+
}
107+
});

0 commit comments

Comments
 (0)