-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from michalvankodev/bundling
Release process for executables for every platform
- Loading branch information
Showing
10 changed files
with
227 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
release: | ||
name: release ${{ matrix.target }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- target: x86_64-unknown-linux-musl | ||
os: ubuntu-latest | ||
archive: tar.gz | ||
- target: x86_64-apple-darwin | ||
os: macos-latest | ||
archive: tar.gz | ||
- target: x86_64-pc-windows-gnu | ||
os: windows-latest | ||
archive: zip | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- uses: Swatinem/rust-cache@v2 | ||
with: | ||
cache-on-failure: true | ||
shared-key: ${{matrix.target}}-cache | ||
|
||
- name: Compile binaries | ||
run: | | ||
cargo build --verbose --release | ||
if [ "${{ matrix.os }}" = "windows-latest" ]; then | ||
bin="target/release/metaframer.exe" | ||
else | ||
bin="target/release/metaframer" | ||
fi | ||
echo "BIN=$bin" >> $GITHUB_ENV | ||
- name: Determine archive name | ||
run: | | ||
echo "ARCHIVE=metaframer-${{ github.event.tag_name }}-${{ matrix.target }}" >> $GITHUB_ENV | ||
- name: Create archive | ||
run: | | ||
mkdir -p "$ARCHIVE" | ||
cp "$BIN" "$ARCHIVE"/ | ||
cp {README.md,LICENSE} "$ARCHIVE"/ | ||
- name: Build archive (zip) | ||
shell: bash | ||
if: matrix.archive == 'zip' | ||
run: | | ||
7z a "$ARCHIVE.zip" "$ARCHIVE" | ||
certutil -hashfile "$ARCHIVE.zip" SHA256 > "$ARCHIVE.zip.sha256" | ||
echo "ASSET=$ARCHIVE.zip" >> $GITHUB_ENV | ||
echo "ASSET_SUM=$ARCHIVE.zip.sha256" >> $GITHUB_ENV | ||
- name: Build archive (Unix) | ||
shell: bash | ||
if: matrix.archive == 'tar.gz' | ||
run: | | ||
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE" | ||
shasum -a 256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256" | ||
echo "ASSET=$ARCHIVE.tar.gz" >> $GITHUB_ENV | ||
echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> $GITHUB_ENV | ||
- name: Upload release archive | ||
run: gh release upload "${{ github.event.tag_name }}" ${{ env.ASSET }} ${{ env.ASSET_SUM }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
use anyhow::Context; | ||
use dirs::{self, config_dir}; | ||
use handlebars::{self, Handlebars}; | ||
use log::debug; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
pub fn get_templates_path(template_name: &str) -> PathBuf { | ||
let config_dir = config_dir().unwrap(); | ||
let dest_path = Path::new(&config_dir) | ||
.join("metaframer/templates/") | ||
.join(template_name); | ||
dest_path | ||
} | ||
|
||
pub fn init_templates_if_needed() -> Result<(), anyhow::Error> { | ||
let default_template_path = get_templates_path("default"); | ||
if default_template_path.exists() { | ||
return Ok(()); | ||
} | ||
copy_default_template()?; | ||
Ok(()) | ||
} | ||
|
||
/** | ||
* Exctracts default templates overwriting if any change was made by user | ||
*/ | ||
pub fn copy_default_template() -> Result<(), anyhow::Error> { | ||
// Create the destination directory if it doesn't exist | ||
let default_template_path = get_templates_path("default"); | ||
fs::create_dir_all(&default_template_path)?; | ||
|
||
// Copy the template files to the destination directory | ||
let default_template_files = [ | ||
("main.svg", include_str!("../templates/default/main.svg")), | ||
( | ||
"iso-icon.svg", | ||
include_str!("../templates/default/iso-icon.svg"), | ||
), | ||
( | ||
"camera-icon.svg", | ||
include_str!("../templates/default/camera-icon.svg"), | ||
), | ||
( | ||
"aperture-icon.svg", | ||
include_str!("../templates/default/aperture-icon.svg"), | ||
), | ||
( | ||
"focal-length-icon.svg", | ||
include_str!("../templates/default/focal-length-icon.svg"), | ||
), | ||
( | ||
"shutter-speed-icon.svg", | ||
include_str!("../templates/default/shutter-speed-icon.svg"), | ||
), | ||
]; | ||
|
||
for (name, content) in default_template_files { | ||
let path = default_template_path.join(name); | ||
fs::write(&path, content)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn register_templates( | ||
template_name: &str, | ||
handlebars: &mut Handlebars, | ||
) -> Result<(), anyhow::Error> { | ||
let templates_path = get_templates_path(template_name); | ||
debug!("{:?} templates path", templates_path); | ||
handlebars | ||
.register_template_file("main", templates_path.join("main.svg")) | ||
.with_context(|| { | ||
format!( | ||
"could not read template file`{:?}` in `{:?}`", | ||
"main.svg".to_string(), | ||
templates_path | ||
) | ||
})?; | ||
|
||
handlebars | ||
.register_template_file("Camera", templates_path.join("camera-icon.svg")) | ||
.with_context(|| { | ||
format!( | ||
"could not read template file`{:?}` in {:?}", | ||
"camera-icon.svg".to_string(), | ||
templates_path | ||
) | ||
})?; | ||
|
||
handlebars | ||
.register_template_file("Aperture", templates_path.join("aperture-icon.svg")) | ||
.with_context(|| { | ||
format!( | ||
"could not read template file`{:?}`", | ||
"aperture-icon.svg".to_string() | ||
) | ||
})?; | ||
handlebars | ||
.register_template_file( | ||
"ShutterSpeed", | ||
templates_path.join("shutter-speed-icon.svg"), | ||
) | ||
.with_context(|| { | ||
format!( | ||
"could not read template file`{:?}`", | ||
"shutter-speed-icon.svg".to_string() | ||
) | ||
})?; | ||
handlebars | ||
.register_template_file("FocalLength", templates_path.join("focal-length-icon.svg")) | ||
.with_context(|| { | ||
format!( | ||
"could not read template file`{:?}`", | ||
"focal-length-icon.svg".to_string() | ||
) | ||
})?; | ||
handlebars | ||
.register_template_file("Iso", templates_path.join("iso-icon.svg")) | ||
.with_context(|| { | ||
format!( | ||
"could not read template file`{:?}`", | ||
"iso-icon.svg".to_string() | ||
) | ||
})?; | ||
Ok(()) | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes