Skip to content

Commit

Permalink
WIP: publish kentik agent package
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Sep 5, 2024
1 parent dc5fe64 commit 95cc328
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 86 deletions.
31 changes: 31 additions & 0 deletions .github/actions/bundle/action.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';

let binary = process.env.BINARY;
let version = process.env.VERSION;

let [name, arch, _, os] = binary.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`;
await io.mkdirP(dir);
await io.cp(name, `${dir}/${name}`);

await exec.exec(`tar -czvf ${bundle} ${prefix}`);

core.setOutput('bundle', bundle);
33 changes: 33 additions & 0 deletions .github/actions/bundle/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: bundle

inputs:
artifact:
required: true
version:
required: true

outputs:
bundle:
value: ${{ steps.bundle.outputs.bundle }}

runs:
using: composite
steps:
- uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact }}
- 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.artifact }}
VERSION: ${{ inputs.version }}
shell: bash
id: bundle
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.bundle.outputs.bundle }}
path: ${{ steps.bundle.outputs.bundle }}
10 changes: 10 additions & 0 deletions .github/actions/bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "bundle",
"type": "module",
"version": "0.0.1",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/io": "^1.1.3"
}
}
34 changes: 34 additions & 0 deletions .github/actions/package/action.yml
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 }}
57 changes: 57 additions & 0 deletions .github/actions/version/action.mjs
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);
23 changes: 23 additions & 0 deletions .github/actions/version/action.yml
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
9 changes: 9 additions & 0 deletions .github/actions/version/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "av",
"type": "module",
"dependencies": {
"@actions/core": "^1.10.1",
"@octokit/rest": "^21.0.2",
"semver": "^7.6.3"
}
}
Loading

0 comments on commit 95cc328

Please sign in to comment.