Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change install from npm scripts postinstall to optionalDependencies #1675

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test

on:
push:
tags:
- v*
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21.x
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Download Go modules
run: go mod download
env:
GOPROXY: https://proxy.golang.org

- name: Build
run: go build -o ./bin/task -v ./cmd/task

- name: publish
- uses: actions/setup-node@v4
with:
node-version: '18.12.1'
registry-url: 'https://registry.npmjs.org'
- run: cd ./packages/task-release && npm run release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
19 changes: 7 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
"name": "@go-task/cli",
"version": "3.37.2",
"description": "A task runner / simpler Make alternative written in Go",
"scripts": {
"postinstall": "go-npm install",
"preuninstall": "go-npm uninstall"
},
"goBinary": {
"name": "task",
"path": "./bin",
"url": "https://github.com/go-task/task/releases/download/v{{version}}/task_{{platform}}_{{arch}}{{archive_ext}}"
},
"files": [],
"repository": {
"type": "git",
Expand All @@ -28,7 +19,11 @@
"url": "https://github.com/go-task/task/issues"
},
"homepage": "https://taskfile.dev",
"dependencies": {
"@go-task/go-npm": "^0.2.0"
"optionalDependencies": {
"@go-task/cli-darwin-x64": "3.34.1",
"@go-task/cli-darwin-arm64": "3.34.1",
"@go-task/cli-linux-x64": "3.34.1",
"@go-task/cli-linux-arm64": "3.34.1",
"@go-task/cli-win32-x64": "3.34.1"
}
}
}
1 change: 1 addition & 0 deletions packages/task-release/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
task-*
34 changes: 34 additions & 0 deletions packages/task-release/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@go-task/cli-{platform}-{arch}",
"version": "{version}",
"description": "A task runner / simpler Make alternative written in Go",
"type": "module",
"scripts": {
"release": "node release.js"
},
"files": [
"bin"
],
"repository": {
"type": "git",
"url": "https://github.com/go-task/task.git"
},
"keywords": [
"task",
"taskfile",
"build-tool",
"task-runner"
],
"author": "Andrey Nering",
"license": "MIT",
"bugs": {
"url": "https://github.com/go-task/task/issues"
},
"os": [
"{platform}"
],
"cpu": [
"{arch}"
],
"homepage": "https://taskfile.dev"
}
86 changes: 86 additions & 0 deletions packages/task-release/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { spawn as spawnCb } from "node:child_process";
import { readFileSync } from "node:fs";
import { cp, mkdir, readdir, rm, writeFile } from "node:fs/promises";
import mainPackage from "../../package.json" assert { type: "json" };

function spawn(command, args, options) {
return new Promise((resolve, reject) => {
const child = spawnCb(command, args, options);
child.on("exit", (code) => {
if (code === 0) {
return resolve();
}
reject(new Error(`Process exited with code ${code}`));
})
});
}

export const platforms = [
{
os: "darwin",
arch: "arm64",
exe: "./bin/task",
},
{
os: "darwin",
goarch: "amd64",
arch: "x64",
exe: "./bin/task",
},
{
os: "linux",
arch: "arm64",
exe: "./bin/task",
},
{
os: "linux",
goarch: "amd64",
arch: "x64",
exe: "./bin/task",
},
{
os: "win32",
goos: "windows",
goarch: "amd64",
arch: "x64",
exe: "./bin/task.exe",
},
];

const packageJson = readFileSync("package.json", "utf-8");

async function createFolder(platform) {
const folder = `task-${platform.os}-${platform.arch}`

console.debug(`Creating folder ${folder}`)
await mkdir(`${folder}/bin`, { recursive: true })
console.debug(`Copying files to ${folder}`)
await writeFile(`${folder}/package.json`, packageJson.replace(/{platform}/g, platform.os).replace(/{arch}/g, platform.arch).replace(/{version}/g, mainPackage.version))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use .replaceAll('{platform}', ...)? don't this we need regex here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the advantages of using replaceAll instead of replace with a global flag?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readers don't need to parse regex in mind

await cp('../../README.md', `${folder}/README.md`)
await cp('../../LICENSE', `${folder}/LICENSE`)
console.debug(`Building ${folder}`)
await spawn("go", ["build", "-o", `${folder}/${platform.exe}`, "-v", "../../cmd/task"], {
env: {
...process.env,
GOOS: platform.goos || platform.os,
GOARCH: platform.goarch || platform.arch,
},
})
return folder;
}

async function publish(platform) {
const folder = await createFolder(platform)
console.debug(`Publishing ${folder}`)
await spawn("npm", ["publish", '--provenance', '--access', 'public', process.env.DRY_RUN ? '--dry-run' : ''], { stdio: "inherit", cwd: folder })
}

async function main() {
const list = await readdir('.', { withFileTypes: true });
await Promise.all(list.filter((entry) => entry.isDirectory() && entry.name.startsWith('task-')).map((entry) => rm(entry.name, { recursive: true, force: true })));
for (const platform of platforms) {
await publish(platform)
}
}

main();