diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000000..2d8a9ee3d0 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -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 }} diff --git a/package.json b/package.json index df8ff9c9d3..7cd84f9b0b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } -} +} \ No newline at end of file diff --git a/packages/task-release/.gitignore b/packages/task-release/.gitignore new file mode 100644 index 0000000000..99e19ca781 --- /dev/null +++ b/packages/task-release/.gitignore @@ -0,0 +1 @@ +task-* \ No newline at end of file diff --git a/packages/task-release/package.json b/packages/task-release/package.json new file mode 100644 index 0000000000..67c1efd46d --- /dev/null +++ b/packages/task-release/package.json @@ -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" +} \ No newline at end of file diff --git a/packages/task-release/release.js b/packages/task-release/release.js new file mode 100644 index 0000000000..68e7a2540f --- /dev/null +++ b/packages/task-release/release.js @@ -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)) + 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();