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 11, 2024
1 parent dc5fe64 commit ae281d7
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 55 deletions.
34 changes: 34 additions & 0 deletions .github/actions/bundle/action.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import fs from 'node:fs/promises';
import * as core from '@actions/core';
import * as exec from '@actions/exec';

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`;
let bin = `${prefix}/bin/${name}`;

await fs.mkdir(dir, { recursive: true });
await fs.copyFile(name, bin);
await fs.chmod(bin, '0755');

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 }}
9 changes: 9 additions & 0 deletions .github/actions/bundle/package.json
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"
}
}
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": "version",
"type": "module",
"dependencies": {
"@actions/core": "^1.10.1",
"@octokit/rest": "^21.0.2",
"semver": "^7.6.3"
}
}
139 changes: 84 additions & 55 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,36 @@ jobs:

version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/version
id: version
outputs:
version: ${{ steps.version.outputs.version }}
version: ${{ steps.version.outputs.version }}
prerelease: ${{ steps.version.outputs.prerelease }}
publish: ${{ steps.version.outputs.publish }}
release: ${{ steps.version.outputs.release }}

bundle:
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl
- armv7-unknown-linux-musleabihf
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: version
run: |
git describe --always --tags > version
date -u +%Y%m%d%H%M%S >> version
case "${{ startsWith(github.ref, 'refs/tags') }}" in
true) VERSION=`sed -n 1p version` ;;
false) VERSION=`sed -n 2p version` ;;
esac
echo "::notice ::kprobe version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
- uses: ./.github/actions/bundle
with:
name: version
path: version
artifact: kprobe-${{ matrix.target }}
version: "v${{ needs.version.outputs.version }}"
if: ${{ contains(needs.version.outputs.publish, 'bundle') }}
needs: [build, version]

package:
runs-on: ubuntu-latest
Expand All @@ -85,64 +95,83 @@ jobs:
arch: armv7
- name: x86_64-unknown-linux-musl
arch: x86_64
continue-on-error: ${{ !startsWith(matrix.target, 'x86_64') }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: kprobe-${{ matrix.target.name }}
- id: package
uses: kentik/pkg@master
- uses: ./.github/actions/package
with:
name: ${{ github.event.repository.name }}
artifact: kprobe-${{ matrix.target.name }}
version: ${{ needs.version.outputs.version }}
arch: ${{ matrix.target.arch }}
format: ${{ matrix.format }}
package: package.yml
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.package.outputs.package }}
path: ${{ steps.package.outputs.package }}
if: ${{ contains(needs.version.outputs.publish, 'package') }}
needs: [build, version]

publish-packages:
publish-bundle:
runs-on: ubuntu-latest
steps:
- uses: ruby/setup-ruby@v1
- uses: actions/checkout@v4
with:
ruby-version: 2.7
fetch-depth: 0
- uses: actions/download-artifact@v4
- run: ls -lR
- uses: actions/create-github-app-token@v1
with:
path: packages
- name: publish packages
run: |
ls -ltR packages
app-id: ${{ vars.KENTIK_MACHINERY_APP_ID }}
private-key: ${{ secrets.KENTIK_MACHINERY_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: packages
id: token
- uses: ncipollo/release-action@v1
with:
token: ${{ steps.token.outputs.token }}
repo: packages
tag: "kprobe/v${{ needs.version.outputs.version }}"
prerelease: ${{ needs.version.outputs.prerelease }}
allowUpdates: false
removeArtifacts: true
artifacts: "kprobe*.tgz/kprobe*.tgz"
if: ${{ contains(needs.version.outputs.publish, 'bundle') }}
needs: [bundle, version]

gem install package_cloud
# publish-packages:
# runs-on: ubuntu-latest
# steps:
# - uses: ruby/setup-ruby@v1
# with:
# ruby-version: 2.7
# - uses: actions/download-artifact@v4
# with:
# path: packages
# - name: publish packages
# run: |
# ls -ltR packages

case "${{ startsWith(github.ref, 'refs/tags') }}" in
true) REPO="${{ github.event.repository.name }}" ;;
false) REPO="${{ github.event.repository.name }}-dev" ;;
esac
# gem install package_cloud

for deb in packages/*.deb/*.deb; do
package_cloud push kentik/$REPO/debian/jessie $deb
package_cloud push kentik/$REPO/debian/stretch $deb
package_cloud push kentik/$REPO/debian/buster $deb
package_cloud push kentik/$REPO/debian/bullseye $deb
# case "${{ needs.version.outputs.prerelease }}" in
# true) REPO="${{ github.event.repository.name }}-dev" ;;
# false) REPO="${{ github.event.repository.name }}" ;;
# esac

package_cloud push kentik/$REPO/ubuntu/focal $deb
package_cloud push kentik/$REPO/ubuntu/bionic $deb
package_cloud push kentik/$REPO/ubuntu/jammy $deb
done
# for deb in packages/*.deb/*.deb; do
# package_cloud push kentik/$REPO/debian/jessie $deb
# package_cloud push kentik/$REPO/debian/stretch $deb
# package_cloud push kentik/$REPO/debian/buster $deb
# package_cloud push kentik/$REPO/debian/bullseye $deb

for rpm in packages/*.rpm/*.rpm; do
package_cloud push kentik/$REPO/el/7 $rpm
package_cloud push kentik/$REPO/el/8 $rpm
package_cloud push kentik/$REPO/el/9 $rpm
done
env:
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
needs: [package, version]
# package_cloud push kentik/$REPO/ubuntu/focal $deb
# package_cloud push kentik/$REPO/ubuntu/bionic $deb
# package_cloud push kentik/$REPO/ubuntu/jammy $deb
# done

# for rpm in packages/*.rpm/*.rpm; do
# package_cloud push kentik/$REPO/el/7 $rpm
# package_cloud push kentik/$REPO/el/8 $rpm
# package_cloud push kentik/$REPO/el/9 $rpm
# done
# env:
# PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
# if ${{ contains(needs.version.outputs.publish, 'package') }}
# needs: [package, version]

0 comments on commit ae281d7

Please sign in to comment.