Skip to content

Commit

Permalink
Build binaries for releases (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
terror authored Jun 14, 2022
1 parent c5ae257 commit 46a34aa
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Release

on:
push:
tags:
- '*'

defaults:
run:
shell: bash

jobs:
all:
name: All

strategy:
fail-fast: false
matrix:
target:
- x86_64-apple-darwin
- x86_64-pc-windows-msvc
- x86_64-unknown-linux-gnu
include:
- target: x86_64-apple-darwin
os: macos-latest
target_rustflags: ''
- target: x86_64-pc-windows-msvc
os: windows-latest
target_rustflags: ''
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
target_rustflags: ''

runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v2

- name: Install Rust Toolchain Components
uses: actions-rs/toolchain@v1
with:
override: true
target: ${{ matrix.target }}
toolchain: stable

- name: Install Linux Dependencies
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get update
sudo apt-get install musl-tools libssl-dev pkg-config
- name: Release Type
id: release-type
run: |
if [[ ${{ github.ref }} =~ ^refs/tags/[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
echo ::set-output name=value::release
else
echo ::set-output name=value::prerelease
fi
- name: Package
id: package
env:
TARGET: ${{ matrix.target }}
REF: ${{ github.ref }}
OS: ${{ matrix.os }}
TARGET_RUSTFLAGS: ${{ matrix.target_rustflags }}
run: ./bin/package
shell: bash

- name: Publish Archive
uses: softprops/action-gh-release@v0.1.5
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
draft: false
files: ${{ steps.package.outputs.archive }}
prerelease: ${{ steps.release-type.outputs.value == 'prerelease' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42 changes: 42 additions & 0 deletions bin/package
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

set -euxo pipefail

VERSION=`basename $REF`
DIST=`pwd`/dist
BIN=present

echo "Packaging $BIN $VERSION for $TARGET..."

echo "Building $BIN..."
RUSTFLAGS="$TARGET_RUSTFLAGS" cargo build --bin $BIN --target $TARGET --release
EXECUTABLE=target/$TARGET/release/$BIN

if [[ $OS == windows-latest ]]; then
EXECUTABLE=$EXECUTABLE.exe
fi

echo "Copying release files..."
mkdir $DIST
cp \
$EXECUTABLE \
Cargo.lock \
Cargo.toml \
LICENSE \
README.md \
$DIST

cd $DIST
echo "Creating release archive..."
case $OS in
ubuntu-latest | macos-latest)
ARCHIVE=$DIST/$BIN-$VERSION-$TARGET.tar.gz
tar czf $ARCHIVE *
echo "::set-output name=archive::$ARCHIVE"
;;
windows-latest)
ARCHIVE=$DIST/$BIN-$VERSION-$TARGET.zip
7z a $ARCHIVE *
echo "::set-output name=archive::`pwd -W`/$BIN-$VERSION-$TARGET.zip"
;;
esac
13 changes: 13 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ fmt-check:
forbid:
./bin/forbid

publish:
#!/usr/bin/env bash
set -euxo pipefail
rm -rf tmp/release
git clone https://github.com/terror/present.git tmp/release
VERSION=`sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1`
cd tmp/release
git tag -a $VERSION -m "Release $VERSION"
git push origin $VERSION
cargo publish
cd ../..
rm -rf tmp/release
run *args:
cargo run -- {{args}}

Expand Down
2 changes: 2 additions & 0 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ impl File {
let mut offset = 0;

let diffs = self.diffs().collect::<Result<Vec<Diff>>>()?;

for mut diff in diffs {
let prev = self.content.len_chars();

diff.offset(offset);

if self.interactive {
Expand Down

0 comments on commit 46a34aa

Please sign in to comment.