Skip to content

Commit

Permalink
Merge pull request #38 from pipelinit/feat/release_automation
Browse files Browse the repository at this point in the history
New release automation
  • Loading branch information
oesgalha committed Sep 22, 2021
2 parents 8f0cdb5 + b67f7f5 commit 3255333
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 17 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Release new version

on:
push:
tags:
- 'v*.*.*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PRERELEASE: true

jobs:
release:
name: Build and publish new release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set current version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: denoland/setup-deno@v1
with:
deno-version: v1.14.0

- name: Build Linux x86_64 binary
env:
BUILD_TARGET: "x86_64-unknown-linux-gnu"
RELEASE_VERSION: "${{ env.RELEASE_VERSION }}"
run: |
cd cli; deno run --unstable --allow-read --allow-write --allow-net --allow-env --allow-run build.ts
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
tags: |
type=semver,pattern={{version}},enable=true
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
build-args: "version=${{ env.RELEASE_VERSION }}"
context: cli/
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build Windows x86_64 binary
env:
BUILD_TARGET: "x86_64-pc-windows-msvc"
RELEASE_VERSION: "${{ env.RELEASE_VERSION }}"
run: |
cd cli
deno run --unstable --allow-read --allow-write --allow-net --allow-env --allow-run build.ts
- name: Build Mac x86_64 binary
env:
BUILD_TARGET: "x86_64-apple-darwin"
RELEASE_VERSION: "${{ env.RELEASE_VERSION }}"
run: |
cd cli
deno run --unstable --allow-read --allow-write --allow-net --allow-env --allow-run build.ts
- name: Build Mac aarch64 binary
env:
BUILD_TARGET: "aarch64-apple-darwin"
RELEASE_VERSION: "${{ env.RELEASE_VERSION }}"
run: |
cd cli
deno run --unstable --allow-read --allow-write --allow-net --allow-env --allow-run build.ts
- name: Publish the release
uses: softprops/action-gh-release@v1
with:
name: "Pipelinit ${{ env.RELEASE_VERSION }}"
prerelease: ${{ env.PRELEASE }}
tag_name: ${{ env.RELEASE_VERSION }}
files: |
cli/bin/pipelinit-${{ env.RELEASE_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
cli/bin/pipelinit-${{ env.RELEASE_VERSION }}-x86_64-pc-windows-msvc.zip
cli/bin/pipelinit-${{ env.RELEASE_VERSION }}-x86_64-apple-darwin.tar.gz
cli/bin/pipelinit-${{ env.RELEASE_VERSION }}-aarch64-apple-darwin.tar.gz
10 changes: 10 additions & 0 deletions cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM debian:11-slim

ARG version
COPY bin/pipelinit-${version}-x86_64-unknown-linux-gnu /pipelinit

VOLUME ["/app"]

WORKDIR /app

ENTRYPOINT ["/pipelinit"]
51 changes: 34 additions & 17 deletions cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { bundle } from "https://deno.land/x/buckets@0.1.0/mod.ts";
import * as esbuild from "https://deno.land/x/esbuild@v0.12.19/mod.js";

import conf from "./buckets.ts";
import { PIPELINIT_VERSION } from "./deps.ts";

const TARGETS = [
"x86_64-unknown-linux-gnu",
Expand All @@ -11,6 +10,24 @@ const TARGETS = [
"aarch64-apple-darwin",
];

const target: string | undefined = Deno.env.get("BUILD_TARGET");
const version: string | undefined = Deno.env.get("RELEASE_VERSION");

if (target && !TARGETS.includes(target)) {
console.error(
`Invalid build target '${target}'. Must be one of:`,
);
console.error(TARGETS.join("\n"));
Deno.exit(1);
}

if (target && !version) {
console.error(
"The environment variable RELEASE_VERSION must be defined if BUILD_TARGET is also defined",
);
Deno.exit(1);
}

// Bundle and minify
await bundle(conf);
const beforeMinify = await Deno.readTextFile(conf.output);
Expand All @@ -20,20 +37,20 @@ const result = await esbuild.transform(beforeMinify, {
await Deno.writeTextFile(conf.output, result.code);
esbuild.stop();

const compile = async function (target?: string) {
const compile = async function (target?: string, version?: string) {
const cmd = [
"deno",
"compile",
"--unstable",
"--allow-read=.",
"--allow-write",
];
if (target) {
if (target && version) {
cmd.push(
"--target",
target,
"--output",
`bin/pipelinit-${PIPELINIT_VERSION}-${target}`,
`bin/pipelinit-${version}-${target}`,
);
} else {
cmd.push("--output", "bin/pipelinit");
Expand All @@ -47,14 +64,14 @@ const compile = async function (target?: string) {
}
};

const tar = async function (target: string) {
const tar = async function (target: string, version: string) {
const p = Deno.run({
cwd: "bin",
cmd: [
"tar",
"-czf",
`pipelinit-${PIPELINIT_VERSION}-${target}.tar.gz`,
`pipelinit-${PIPELINIT_VERSION}-${target}`,
`pipelinit-${version}-${target}.tar.gz`,
`pipelinit-${version}-${target}`,
],
});

Expand All @@ -64,14 +81,14 @@ const tar = async function (target: string) {
}
};

const zip = async function (target: string) {
const zip = async function (target: string, version: string) {
const p = Deno.run({
cwd: "bin",
cmd: [
"zip",
"-9",
`pipelinit-${PIPELINIT_VERSION}-${target}.zip`,
`pipelinit-${PIPELINIT_VERSION}-${target}.exe`,
`pipelinit-${version}-${target}.zip`,
`pipelinit-${version}-${target}.exe`,
],
});

Expand All @@ -81,18 +98,18 @@ const zip = async function (target: string) {
}
};

const compress = async function (target: string) {
const compress = async function (target: string, version: string) {
if (target === "x86_64-pc-windows-msvc") {
await zip(target);
await zip(target, version);
} else {
await tar(target);
await tar(target, version);
}
};

await compile();
for (const target of TARGETS) {
await compile(target);
await compress(target);
await compile(target, version);

if (target && version) {
await compress(target, version);
}

await Deno.remove(conf.output);

0 comments on commit 3255333

Please sign in to comment.