diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..196df17 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,66 @@ +name: release + +on: + push: + tags: + - v* + +jobs: + create_release: + runs-on: ubuntu-latest + outputs: + upload_url: ${{steps.create_release.outputs.upload_url}} + steps: + - name: Create release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + with: + tag_name: ${{github.ref}} + release_name: ${{github.ref}} + draft: false + prerelease: false + build: + needs: create_release + runs-on: ${{matrix.os}} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + os_name: linux + - os: macos-latest + os_name: macos + - os: windows-latest + os_name: windows + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Check project + uses: actions-rs/cargo@v1 + with: + command: check + - name: Build release + uses: actions-rs/cargo@v1 + with: + command: build + args: --release + - name: Rename executable + if: matrix.os_name == 'linux' || matrix.os_name == 'macos' + run: mv target/release/himalaya target/release/himalaya.exe + - name: Compress executable + run: tar czf himalaya.tar.gz -C target/release himalaya.exe + - name: Upload release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + with: + upload_url: ${{needs.create_release.outputs.upload_url}} + asset_path: himalaya.tar.gz + asset_name: himalaya-${{matrix.os_name}}.tar.gz + asset_content_type: application/gzip diff --git a/src/io.rs b/src/io.rs index 7bc69d6..80de57d 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,6 +1,5 @@ use std::{ - env::temp_dir, - fmt, + env, fmt, fs::{remove_file, File}, io::{self, Read, Write}, process::{Command, Output}, @@ -12,7 +11,8 @@ use std::{ #[derive(Debug)] pub enum Error { IoError(io::Error), - AskForSendingConfirmationError, + GetEditorEnvVarNotFoundError(env::VarError), + AskForConfirmationDeniedError, } impl fmt::Display for Error { @@ -21,7 +21,8 @@ impl fmt::Display for Error { match self { Error::IoError(err) => err.fmt(f), - Error::AskForSendingConfirmationError => write!(f, "action cancelled"), + Error::GetEditorEnvVarNotFoundError(err) => err.fmt(f), + Error::AskForConfirmationDeniedError => write!(f, "action cancelled"), } } } @@ -32,6 +33,12 @@ impl From for Error { } } +impl From for Error { + fn from(err: env::VarError) -> Error { + Error::GetEditorEnvVarNotFoundError(err) + } +} + // Result wrapper type Result = result::Result; @@ -40,12 +47,14 @@ type Result = result::Result; pub fn open_editor_with_tpl(tpl: &[u8]) -> Result { // Creates draft file - let mut draft_path = temp_dir(); + let mut draft_path = env::temp_dir(); draft_path.push("himalaya-draft.mail"); File::create(&draft_path)?.write(tpl)?; // Opens editor and saves user input to draft file - Command::new(env!("EDITOR")).arg(&draft_path).status()?; + Command::new(env::var("EDITOR")?) + .arg(&draft_path) + .status()?; // Extracts draft file content let mut draft = String::new(); @@ -66,7 +75,7 @@ pub fn ask_for_confirmation(prompt: &str) -> Result<()> { .map(|bytes| bytes as char) { Some('y') | Some('Y') => Ok(()), - _ => Err(Error::AskForSendingConfirmationError), + _ => Err(Error::AskForConfirmationDeniedError), } }