-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
281 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,52 +4,184 @@ on: | |
push: | ||
branches: | ||
- master | ||
tags: | ||
- v* | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test: | ||
name: Native | ||
build-test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
node-version: [12.x] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Cache esy dependencies | ||
uses: actions/cache@v1 | ||
id: cache | ||
with: | ||
path: _export | ||
key: ${{ runner.OS }}-build-${{ hashFiles('esy.lock/index.json') }} | ||
restore-keys: | | ||
${{ runner.OS }}-build-${{ env.cache-name }}- | ||
${{ runner.OS }}-build- | ||
${{ runner.OS }}- | ||
node-version: 12 | ||
- name: Install esy | ||
run: npm install -g [email protected].6 | ||
run: npm install -g [email protected].7 | ||
|
||
- name: Import dependencies | ||
if: steps.cache.outputs.cache-hit == 'true' | ||
run: esy import-build _export/* | ||
- name: Try to restore install cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.esy/source | ||
key: source-${{ matrix.os }}-${{ hashFiles('**/index.json') }} | ||
|
||
- name: Install dependencies | ||
run: esy install | ||
|
||
- name: Build | ||
- name: Print esy cache | ||
id: print_esy_cache | ||
run: node .github/workflows/print-esy-cache.js | ||
|
||
- name: Try to restore dependencies cache | ||
id: deps-cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.print_esy_cache.outputs.esy_cache }} | ||
key: build-${{ matrix.os }}-${{ hashFiles('**/index.json') }} | ||
restore-keys: build-${{ matrix.os }}- | ||
|
||
- name: Build dependencies | ||
if: steps.deps-cache.outputs.cache-hit != 'true' | ||
run: esy build-dependencies | ||
|
||
- name: Build project | ||
run: esy build | ||
|
||
- name: Run tests | ||
- name: Run Native tests | ||
run: esy test | ||
|
||
- name: Export dependencies | ||
run: esy export-dependencies | ||
- name: Create npm package | ||
run: esy npm-release | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: ${{ matrix.os }} | ||
path: _release/ | ||
|
||
# Cleanup build cache if dependencies have changed | ||
- name: Clean build cache | ||
if: steps.deps-cache.outputs.cache-hit != 'true' | ||
run: esy cleanup . | ||
|
||
prepare-publish: | ||
name: Prepare publish to npm | ||
needs: build-test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
- uses: actions/checkout@v2 | ||
|
||
# Download platform artifacts | ||
- name: Download Linux release | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: ubuntu-latest | ||
path: ubuntu-latest | ||
- name: Download Windows release | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: windows-latest | ||
path: windows-latest | ||
- name: Download macOS release | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: macos-latest | ||
path: macos-latest | ||
# Move artifacts in place | ||
- name: Move artifacts | ||
run: | | ||
mkdir -p _release/platform-linux | ||
mkdir -p _release/platform-windows-x64 | ||
mkdir -p _release/platform-darwin | ||
cp -a ubuntu-latest/. _release/platform-linux | ||
cp -a windows-latest/. _release/platform-windows-x64 | ||
cp -a macos-latest/. _release/platform-darwin | ||
- name: Prepare package | ||
run: node .github/workflows/release.js | ||
# Create a npm package that can easily be published and tested | ||
- name: npm pack | ||
run: npm pack . | ||
working-directory: _release | ||
- name: move package | ||
run: mv _release/*.tgz react-rules-of-hooks-ppx.tgz | ||
# Upload artifacts | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: release | ||
path: _release/ | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: release-tarball | ||
path: react-rules-of-hooks-ppx.tgz | ||
|
||
publish: | ||
needs: prepare-publish | ||
name: (only on release) Publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js 12.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12.x | ||
|
||
- name: Print short SHA | ||
id: sha | ||
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" | ||
|
||
- name: Download release | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: release | ||
path: release | ||
|
||
- name: Zip release folder | ||
run: zip -r release.zip release | ||
|
||
- name: Create GitHub release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Upload ubuntu-latest to Github release | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: release.zip | ||
asset_name: release.zip | ||
asset_content_type: application/gzip | ||
|
||
- name: Release nightly NPM package | ||
if: github.event_name == 'pull_request' | ||
run: | | ||
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN | ||
npm version prerelease --preid nightly.${{ steps.sha.outputs.sha_short }} -no-git-tag-version | ||
npm publish --access public --tag nightly | ||
working-directory: ./_release | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} | ||
|
||
- name: Release NPM package | ||
if: "startsWith(github.ref, 'refs/tags/v')" | ||
run: | | ||
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN | ||
npm publish --access public | ||
working-directory: ./_release | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const fs = require("fs"); | ||
const os = require("os"); | ||
const path = require("path"); | ||
|
||
const ESY_FOLDER = process.env.ESY__PREFIX | ||
? process.env.ESY__PREFIX | ||
: path.join(os.homedir(), ".esy"); | ||
const esy3 = fs | ||
.readdirSync(ESY_FOLDER) | ||
.filter((name) => name.length > 0 && name[0] === "3") | ||
.sort() | ||
.pop(); | ||
console.log(`::set-output name=esy_cache::${path.join(ESY_FOLDER, esy3, "i")}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
console.log("Creating package.json"); | ||
|
||
// From the project root pwd | ||
const mainPackageJsonPath = fs.existsSync("esy.json") | ||
? "esy.json" | ||
: "package.json"; | ||
|
||
const exists = fs.existsSync(mainPackageJsonPath); | ||
|
||
if (!exists) { | ||
console.error("No package.json or esy.json at " + mainPackageJsonPath); | ||
process.exit(1); | ||
} | ||
|
||
// Now require from this script's location. | ||
const mainPackageJson = require(path.join("..", "..", mainPackageJsonPath)); | ||
const bins = Array.isArray(mainPackageJson.esy.release.bin) | ||
? mainPackageJson.esy.release.bin.reduce( | ||
(acc, curr) => Object.assign({ [curr]: "bin/" + curr }, acc), | ||
{} | ||
) | ||
: Object.keys(mainPackageJson.esy.release.bin).reduce( | ||
(acc, currKey) => | ||
Object.assign( | ||
{ [currKey]: "bin/" + mainPackageJson.esy.release.bin[currKey] }, | ||
acc | ||
), | ||
{} | ||
); | ||
|
||
const rewritePrefix = | ||
mainPackageJson.esy && | ||
mainPackageJson.esy.release && | ||
mainPackageJson.esy.release.rewritePrefix; | ||
|
||
const packageJson = JSON.stringify( | ||
{ | ||
...mainPackageJson, | ||
scripts: { | ||
postinstall: rewritePrefix | ||
? "ESY_RELEASE_REWRITE_PREFIX=true node ./postinstall.js" | ||
: "node ./postinstall.js", | ||
}, | ||
bin: bins, | ||
files: [ | ||
"_export/", | ||
"bin/", | ||
"postinstall.js", | ||
"esyInstallRelease.js", | ||
"platform-linux/", | ||
"platform-darwin/", | ||
"platform-windows-x64/", | ||
], | ||
}, | ||
null, | ||
2 | ||
); | ||
|
||
fs.writeFileSync( | ||
path.join(__dirname, "..", "..", "_release", "package.json"), | ||
packageJson, | ||
{ | ||
encoding: "utf8", | ||
} | ||
); | ||
|
||
try { | ||
console.log("Copying LICENSE"); | ||
fs.copyFileSync( | ||
path.join(__dirname, "..", "..", "LICENSE"), | ||
path.join(__dirname, "..", "..", "_release", "LICENSE") | ||
); | ||
} catch (e) { | ||
console.warn("No LICENSE found"); | ||
} | ||
|
||
console.log("Copying README.md"); | ||
fs.copyFileSync( | ||
path.join(__dirname, "..", "..", "README.md"), | ||
path.join(__dirname, "..", "..", "_release", "README.md") | ||
); | ||
|
||
console.log("Copying postinstall.js"); | ||
fs.copyFileSync( | ||
path.join(__dirname, "release-postinstall.js"), | ||
path.join(__dirname, "..", "..", "_release", "postinstall.js") | ||
); | ||
|
||
console.log("Creating placeholder files"); | ||
const placeholderFile = `:; echo "You need to have postinstall enabled"; exit $? | ||
@ECHO OFF | ||
ECHO You need to have postinstall enabled`; | ||
fs.mkdirSync(path.join(__dirname, "..", "..", "_release", "bin")); | ||
|
||
Object.keys(bins).forEach((name) => { | ||
if (bins[name]) { | ||
const binPath = path.join(__dirname, "..", "..", "_release", bins[name]); | ||
fs.writeFileSync(binPath, placeholderFile); | ||
fs.chmodSync(binPath, 0777); | ||
} else { | ||
console.log("bins[name] name=" + name + " was empty. Weird."); | ||
console.log(bins); | ||
} | ||
}); |
Oops, something went wrong.