Skip to content

Commit

Permalink
Build releases using GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Oct 15, 2019
1 parent cff6c5d commit 54eb1b9
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 196 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/rust.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
name: Rust
name: Build

on: [push, pull_request]
on:
push:
branches:
- master
pull_request: {}

jobs:
build:
name: Build and Test
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
- name: Checkout
uses: actions/checkout@v1
- name: Setup Toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: beta
override: true
- name: cargo build
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --all
- name: cargo test
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
tags:
- '*'

jobs:
build:
name: Release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-latest, windows-latest, ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: beta
override: true
- name: Build
uses: actions-rs/cargo@v1
with:
command: run
args: --manifest-path=tools/builder/Cargo.toml
- name: Create Release
uses: softprops/action-gh-release@v1
with:
draft: true
files: target/upload/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

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.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<p align="center">
<a href="https://github.com/udoprog/OxidizeBot/actions">
<img alt="GitHub Actions Build Status" src="https://github.com/udoprog/OxidizeBot/workflows/Rust/badge.svg">
<img alt="GitHub Actions Build Status" src="https://github.com/udoprog/OxidizeBot/workflows/Build/badge.svg">
</a>
</p>

Expand Down
39 changes: 0 additions & 39 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion bot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxidize"
version = "1.0.1"
version = "0.0.0"
authors = ["John-John Tedro <[email protected]>"]
edition = "2018"
license = "MIT/Apache-2.0"
Expand Down
61 changes: 59 additions & 2 deletions bot/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
fn main() {
use failure::{format_err, ResultExt as _};
use std::{env, fs, path::PathBuf, process::Command};

type Result<T> = std::result::Result<T, failure::Error>;

fn version() -> Result<String> {
if let Ok(version) = env::var("OXIDIZE_VERSION") {
return Ok(version);
}

let output = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()?;

let version = std::str::from_utf8(&output.stdout)?;
Ok(format!("git-{}", version))
}

/// Construct a Windows version information.
fn file_version() -> Option<(String, u64)> {
let version = match env::var("OXIDIZE_FILE_VERSION") {
Ok(version) => version,
Err(_) => return None,
};

let mut info = 0u64;

let mut it = version.split('.');

info |= it.next()?.parse().unwrap_or(0) << 48;
info |= it.next()?.parse().unwrap_or(0) << 32;
info |= it.next()?.parse().unwrap_or(0) << 16;
info |= match it.next() {
Some(n) => n.parse().unwrap_or(0),
None => 0,
};

Some((version, info))
}

fn main() -> Result<()> {
let version = version()?;

if cfg!(target_os = "windows") {
use winres::VersionInfo::*;

let mut res = winres::WindowsResource::new();
res.set_icon("res/icon.ico");
res.compile().unwrap();

if let Some((version, info)) = file_version() {
res.set("FileVersion", &version);
res.set("ProductVersion", &version);
res.set_version_info(FILEVERSION, info);
res.set_version_info(PRODUCTVERSION, info);
}

res.compile().context("compiling resorces")?;
}

let out_dir =
PathBuf::from(env::var_os("OUT_DIR").ok_or_else(|| format_err!("missing: OUT_DIR"))?);
fs::write(out_dir.join("version.txt"), &version).context("writing version.txt")?;
Ok(())
}
2 changes: 1 addition & 1 deletion bot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate smallvec;

pub use async_injector as injector;

pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version.txt"));

#[macro_use]
mod macros;
Expand Down
Loading

0 comments on commit 54eb1b9

Please sign in to comment.