From 5cf8f39bba4a513cc0c25712015cbdd6720640e7 Mon Sep 17 00:00:00 2001 From: leon3s Date: Fri, 12 May 2023 17:54:37 +0200 Subject: [PATCH] prepare release --- .github/workflows/draft_nightly.yml | 64 +++++++++++++++++++++++++++++ Cargo.toml | 10 ++++- README.md | 14 ++++++- changelog.md | 12 ++++++ scripts/release.sh | 23 +++++++++++ src/main.rs | 6 +-- 6 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/draft_nightly.yml create mode 100644 changelog.md create mode 100755 scripts/release.sh diff --git a/.github/workflows/draft_nightly.yml b/.github/workflows/draft_nightly.yml new file mode 100644 index 0000000..5f453c1 --- /dev/null +++ b/.github/workflows/draft_nightly.yml @@ -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 }} diff --git a/Cargo.toml b/Cargo.toml index b2e9387..820be2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,16 @@ name = "c2ncl" version = "0.0.1" edition = "2021" +authors = ["Next Hat Contributors "] +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" diff --git a/README.md b/README.md index cae324a..a610b5d 100644 --- a/README.md +++ b/README.md @@ -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 Path to docker-compose file [default: ./docker-compose.yml] + -o, --out-file Output filepath [default: ./StateFile.yml] + -h, --help Print help + -V, --version Print version + ``` diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..c754b7d --- /dev/null +++ b/changelog.md @@ -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` diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..f209056 --- /dev/null +++ b/scripts/release.sh @@ -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} diff --git a/src/main.rs b/src/main.rs index c71e5b9..be6e9d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, } @@ -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;