-
Notifications
You must be signed in to change notification settings - Fork 4
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
Will
committed
Sep 12, 2024
1 parent
dc5fe64
commit 23cb890
Showing
8 changed files
with
278 additions
and
29 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import fs from 'node:fs/promises'; | ||
import * as core from '@actions/core'; | ||
import * as exec from '@actions/exec'; | ||
|
||
let binary = process.env.BINARY; | ||
let name = process.env.NAME; | ||
let target = process.env.TARGET; | ||
let version = process.env.VERSION; | ||
|
||
let [arch, _, os] = target.split('-'); | ||
|
||
switch (arch) { | ||
case 'aarch64': | ||
arch = 'arm64'; | ||
break; | ||
case 'armv7': | ||
arch = 'arm'; | ||
break; | ||
case 'x86_64': | ||
arch = 'amd64'; | ||
break; | ||
} | ||
|
||
let bundle = `${name}_${version}_${os}_${arch}.tgz`; | ||
let prefix = `${name}-${version}`; | ||
|
||
let dir = `${prefix}/bin`; | ||
let bin = `${prefix}/bin/${binary}`; | ||
|
||
await fs.mkdir(dir, { recursive: true }); | ||
await fs.copyFile(binary, bin); | ||
await fs.chmod(bin, '0755'); | ||
|
||
await exec.exec(`tar -czvf ${bundle} ${prefix}`); | ||
|
||
core.setOutput('bundle', bundle); |
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,39 @@ | ||
name: bundle | ||
|
||
inputs: | ||
binary: | ||
required: true | ||
name: | ||
required: true | ||
target: | ||
required: true | ||
version: | ||
required: true | ||
|
||
outputs: | ||
bundle: | ||
value: ${{ steps.bundle.outputs.bundle }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ inputs.binary }}-${{ inputs.target }} | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm install $GITHUB_ACTION_PATH | ||
shell: bash | ||
- run: node $GITHUB_ACTION_PATH/action.mjs | ||
env: | ||
BINARY: ${{ inputs.binary }} | ||
NAME: ${{ inputs.name }} | ||
TARGET: ${{ inputs.target }} | ||
VERSION: ${{ inputs.version }} | ||
shell: bash | ||
id: bundle | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ steps.bundle.outputs.bundle }} | ||
path: ${{ steps.bundle.outputs.bundle }} |
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,9 @@ | ||
{ | ||
"name": "bundle", | ||
"type": "module", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"@actions/core": "^1.10.1", | ||
"@actions/exec": "^1.1.1" | ||
} | ||
} |
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,34 @@ | ||
name: package | ||
|
||
inputs: | ||
artifact: | ||
required: true | ||
version: | ||
required: true | ||
arch: | ||
required: true | ||
format: | ||
required: true | ||
|
||
outputs: | ||
bundle: | ||
value: ${{ steps.bundle.outputs.bundle }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ inputs.artifact }} | ||
- uses: kentik/pkg@master | ||
with: | ||
name: ${{ github.event.repository.name }} | ||
version: ${{ inputs.version }} | ||
arch: ${{ inputs.arch }} | ||
format: ${{ inputs.format }} | ||
package: package.yml | ||
id: package | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ steps.package.outputs.package }} | ||
path: ${{ steps.package.outputs.package }} |
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,57 @@ | ||
import { env } from 'node:process'; | ||
import { Octokit } from '@octokit/rest'; | ||
import { notice, setOutput } from '@actions/core'; | ||
import { inc, parse, valid } from 'semver'; | ||
|
||
let octokit = new Octokit({ auth: env.GITHUB_TOKEN }); | ||
let github = octokit.rest; | ||
|
||
let [owner, repo] = env.GITHUB_REPOSITORY.split('/'); | ||
let ref = env.GITHUB_REF; | ||
let build = env.GITHUB_RUN_NUMBER ?? 0; | ||
|
||
let result = { | ||
'version': 'INVALID', | ||
'prerelease': false, | ||
'publish': [], | ||
'release': false, | ||
} | ||
|
||
if (ref.startsWith('refs/tags/')) { | ||
let [,, tag] = ref.split('/'); | ||
let version = parse(`v${tag}`); | ||
|
||
if (version) { | ||
result.version = version.version; | ||
result.prerelease = version.prerelease.length > 0; | ||
result.publish = ['bundle', 'package']; | ||
result.release = true; | ||
} | ||
} else { | ||
let branch = 'unknown'; | ||
|
||
if (ref.startsWith('refs/heads/')) { | ||
branch = ref.split('/')[2]; | ||
} | ||
|
||
let res = await github.repos.listTags({ owner, repo }); | ||
let tag = res?.data?.[0]?.name ?? '0.0.0'; | ||
let version = parse(`v${tag}`); | ||
|
||
if (version) { | ||
version = inc(version, 'prerelease', `${branch}.${build}`, false); | ||
result.version = version; | ||
result.prerelease = true; | ||
result.publish = ['bundle']; | ||
result.release = false; | ||
} | ||
} | ||
|
||
notice(`version ${result.version}`); | ||
|
||
console.log(result); | ||
|
||
setOutput('version', result.version); | ||
setOutput('prerelease', result.prerelease); | ||
setOutput('publish', result.publish.join(',')); | ||
setOutput('release', result.release); |
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,23 @@ | ||
name: version | ||
|
||
outputs: | ||
version: | ||
value: ${{ steps.version.outputs.version }} | ||
prerelease: | ||
value: ${{ steps.version.outputs.prerelease }} | ||
publish: | ||
value: ${{ steps.version.outputs.publish }} | ||
release: | ||
value: ${{ steps.version.outputs.release }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm install $GITHUB_ACTION_PATH | ||
shell: bash | ||
- run: node $GITHUB_ACTION_PATH/action.mjs | ||
shell: bash | ||
id: version |
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,9 @@ | ||
{ | ||
"name": "version", | ||
"type": "module", | ||
"dependencies": { | ||
"@actions/core": "^1.10.1", | ||
"@octokit/rest": "^21.0.2", | ||
"semver": "^7.6.3" | ||
} | ||
} |
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