Skip to content

Commit

Permalink
prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
leon3s committed May 12, 2023
1 parent 3ef1c36 commit 5cf8f39
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 6 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/draft_nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Draft Nightly c2ncl

on:
push:
branches:
- "release-nightly-*"
pull_request:
branches:
- "release-nightly-*"
types: [opened, synchronize, closed]

env:
CARGO_TERM_COLOR: always

jobs:
release_image:
runs-on: ubuntu-latest
container: rust:1.69.0-alpine3.17

steps:
# Install required dependencies
- name: Install dependencies
run: |
apk add --update alpine-sdk musl-dev g++ make libpq-dev openssl-dev git upx perl build-base dpkg pandoc github-cli
rustup target add x86_64-unknown-linux-musl
- uses: actions/checkout@v3
# Extract branch info
- name: Set info
run: |
echo "BRANCH_NAME=c2ncl" >> $GITHUB_ENV
echo "CHANNEL=$(echo ${GITHUB_REF##*/} | awk -F- '{print $2}')" >> $GITHUB_ENV
echo "VERSION=$(echo ${GITHUB_REF##*/} | awk -F- '{print $3}')" >> $GITHUB_ENV
# Fix git permission
- name: Fix git permission
run: |
git config --global --add safe.directory /__w/c2ncl/c2ncl
# Print info for debug
- name: Print Info
run: |
echo $BRANCH_NAME
echo $BINARY_NAME
echo $CHANNEL
echo $VERSION
# Package c2ncl into a .deb
- name: Package
run: ./scripts/release_c2ncl.sh
- name: Test if release already exists
id: release-exists
continue-on-error: true
run: gh release view $BINARY_NAME-$VERSION-$CHANNEL
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
- name: Create new draft release
if: steps.release-exists.outcome == 'failure' && steps.release-exists.conclusion == 'success'
run: gh release create -d $BINARY_NAME-$VERSION-$CHANNEL -t $BINARY_NAME-$VERSION-$CHANNEL -F changelog.md target/debian/${BINARY_NAME}_${VERSION}_amd64.deb#c2ncl_amd64.deb
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
- name: Update draft release
if: steps.release-exists.outcome == 'success' && steps.release-exists.conclusion == 'success'
run: |
gh release delete-asset -y $BINARY_NAME-$VERSION-$CHANNEL ${BINARY_NAME}_${VERSION}_amd64.deb || true
gh release upload $BINARY_NAME-$VERSION-$CHANNEL target/debian/${BINARY_NAME}_${VERSION}_amd64.deb#c2ncl_amd64.deb
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
name = "c2ncl"
version = "0.0.1"
edition = "2021"
authors = ["Next Hat Contributors <[email protected]>"]
description = "Converts docker-compose.yml to nanocl StateFile.yml"
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# Profile optimised for binary size
[profile.release]
opt-level = "z"
strip = true
lto = true
codegen-units = 1

[dependencies]
anyhow = "1.0.71"
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# c2ncl

Compose to nanocl converts docker-compose file to nanocl config
Convert `docker-compose.yml` to `StateFile.yml`

## Usage

```sh
c2ncl -c ../../docker-compose.yml ./example.Statefile
$ c2ncl --help
Converts docker-compose.yml to nanocl StateFile.yml

Usage: c2ncl [OPTIONS]

Options:
-i, --in-file <IN_FILE> Path to docker-compose file [default: ./docker-compose.yml]
-o, --out-file <OUT_FILE> Output filepath [default: ./StateFile.yml]
-h, --help Print help
-V, --version Print version

```
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.1] 2023-04-30

### Added

- Convert `docker-compose.yml` to `StateFile.yml`
23 changes: 23 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# This script is used to release a new version of the project.

arch=amd64
pkg_name="c2ncl"
version=$(cat Cargo.toml | grep -m 1 "version = \"" | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')
release_path="./target/${pkg_name}_${version}_${arch}"

# Clear existing .deb package directory
rm -fr "${release_path}"
# Create new directories structure for .deb package
mkdir -p "${release_path}"
mkdir -p "${release_path}"/DEBIAN
mkdir -p "${release_path}"/usr/local/bin
mkdir -p "${release_path}"/usr/local/man/man1

# Build static binary
export RUSTFLAGS="-C target-feature=+crt-static"
cargo build --release --target x86_64-unknown-linux-musl

# Pack the binary to reduce size
upx --best --lzma ./target/x86_64-unknown-linux-musl/release/${pkg_name}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use clap::Parser;
struct Args {
/// Path to docker-compose file
#[arg(short, long, default_value = "./docker-compose.yml")]
compose_file: String,
in_file: String,

/// Output filepath
#[arg(short, long, default_value = "./StateFile")]
#[arg(short, long, default_value = "./StateFile.yml")]
out_file: String,
}

Expand All @@ -45,7 +45,7 @@ fn write_compose_file(
fn main() -> Result<()> {
let args = Args::parse();

let input_file = &args.compose_file;
let input_file = &args.in_file;

let output_file = &args.out_file;

Expand Down

0 comments on commit 5cf8f39

Please sign in to comment.