Skip to content

Commit

Permalink
👷 Added release on tag CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
vasigorc committed May 4, 2024
1 parent 5950e99 commit 0a46dad
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 2 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/package-on-tag-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Package and Attach Artifacts for the Project

on:
push:
tags:
- 'v*' # Trigger when a new tag is created, typically for releases

env:
CARGO_TERM_COLOR: always
DEB_DIR: target/debian
RPM_DIR: target/generate-rpm

jobs:
package-on-tag-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache cargo-deb and cargo-generate-rpm
uses: actions/cache@v2
with:
path: |
~/.cargo/bin
key: ${{ runner.os }}-cargo-tools-${{ hashFiles('**/*.toml') }}
restore-keys: |
${{ runner.os }}-cargo-tools-
- name: Install cargo-deb and cargo-generate-rpm
run: |
if ! command -v cargo-deb &> /dev/null; then
cargo install cargo-deb
fi
if ! command -v cargo-generate-rpm &> /dev/null; then
cargo install cargo-generate-rpm
fi
- name: Package as .deb
run: cargo deb --fast
- name: Package as .rpm
run: |
cargo build --release
strip -s target/release/knapsack_problem
cargo generate-rpm
- name: List packaged files
run: ls ${{ env.DEB_DIR }} && ls ${{ env.RPM_DIR }}
- name: Archive .deb and .rpm
uses: actions/upload-artifact@v2
with:
name: packaged-artifacts
path: |
${{ env.DEB_DIR }}/*.deb
${{ env.RPM_DIR }}/*.rpm
- name: Get Tag Information
id: tag_info # Change the ID to reflect multiple outputs
run: |
tag="${{ github.ref }}"
tag_name="${tag#refs/tags/}"
tag_message=$(git tag -l --format='%(contents)' "$tag_name")
echo "tag_name=$tag_name" >> $GITHUB_ENV # Set the tag name in GITHUB_ENV
echo "tag_message=$tag_message" >> $GITHUB_ENV # Set the tag message in GITHUB_ENV
shell: bash
- name: Ensure GitHub Release exists
run: |
gh release create "${{ env.tag_name }}" -t "Release ${{ env.tag_name }}" -n "${{ env.tag_message }}" # Use the tag message for the description
sleep 5 # Allow time for the release to be fully created
gh release list # Check if the release is created
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Attach Artifacts to Release
run: |
gh release upload "${{ env.tag_name }}" ${{ env.DEB_DIR }}/*.deb ${{ env.RPM_DIR }}/*.rpm # Correct tag reference
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[package]
name = "knapsack_problem"
version = "0.1.0"
version = "0.0.1"
edition = "2021"
description = "Rust code for solving typical dynamic programming programming exercise 'Knapscack problem'"
license = "MIT"
authors = ["Vasile Gorcinschi <[email protected]>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -19,3 +22,35 @@ clippy = "0.0.302"
expectest = "0.12.0"
rstest = "0.18.2"
rustfmt = "0.10.0"

[package.metadata.generate-rpm]
release = "1" # RPM package release number
summary = "Knapsack Problem Solver"
license = "MIT"
packager = "Vasile Gorcinschi <[email protected]>"
assets = [
{ source = "target/release/knapsack_problem", dest = "/usr/bin/knapsack_problem", mode = "0755", user = "root", group = "root" },
{ source = "README.md", dest = "/usr/share/doc/knapsack_problem/README.md", mode = "0644", doc = true },
]

[package.metadata.deb]
maintainer = "Vasile Gorcinschi <[email protected]>"
copyright = "2024, Vasile Gorcinschi"
extended-description = """\
Rust code for solving the Knapsack Problem.
A typical dynamic programming exercise."""
depends = "$auto" # Automatically detect dependencies
section = "Utilities"
priority = "optional"
assets = [
[
"target/release/knapsack_problem",
"usr/bin/",
"0755",
], # Executable with permissions
[
"README.md",
"usr/share/doc/knapsack_problem/README.md",
"0644",
], # Documentation
]

0 comments on commit 0a46dad

Please sign in to comment.