Skip to content

Commit

Permalink
ci: macos binaries and homebrew (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
chevdor committed Jun 17, 2021
1 parent 5085186 commit 5655d6b
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 21 deletions.
81 changes: 79 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,83 @@ jobs:
name: linux
path: "tera-cli_linux_amd64.deb"

macos:
env:
TARGET_DIR: target/release

runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Get Release Version
run: |
echo GITHUB_REF=$GITHUB_REF
RELEASE_VERSION=${GITHUB_REF#refs/*/}
RAW_VERSION=${RELEASE_VERSION:1}
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "RAW_VERSION=$RAW_VERSION" >> $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy

- name: Check tooling
shell: bash
run: |
tar --version
shasum --version
- name: Build MacOS binary
shell: bash
run: |
cargo build --release
# echo "${{ github.workspace }}/${{ env.TARGET_DIR }}" >> $GITHUB_PATH
cp "${{ env.TARGET_DIR }}/tera" /usr/local/bin
- name: Compress & sha256
run: |
tar -czf ${{ env.TARGET_DIR }}/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz -C ${{ env.TARGET_DIR }} tera
SHA256=$(shasum -a 256 ${{ env.TARGET_DIR }}/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz | awk '{ print $1}' | tee ${{ env.TARGET_DIR }}/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz.sha256)
echo SHA256: $SHA256
echo "SHA256=$SHA256" >> $GITHUB_ENV
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: macos
path: |
${{ env.TARGET_DIR }}/tera
${{ env.TARGET_DIR }}/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz
${{ env.TARGET_DIR }}/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz.sha256
# We do that before checking out master (in case we were not in master already)
- name: Prepare new Formula
env:
NAME: Tera
DESCRIPTION: "A command line utility written in Rust to render templates using the tera templating engine"
SITE: https://github.com
REPO: chevdor/tera-cli
SHA256: ${{env.SHA256}}
VERSION: ${{env.RAW_VERSION}}
run: |
tera --version
tera --template templates/formula.rb --env-only > $HOME/tera.rb
cat $HOME/tera.rb
- name: Update Homebrew Formula
if: github.ref == 'refs/heads/master'
run: |
cp -f $HOME/tera.rb Formula/tera.rb
git config --global user.name 'TeraBot'
git config --global user.email 'chevdor@users.noreply.github.com'
git commit Formula/tera.rb -m "build: new homebrew formula for ${{ env.RELEASE_VERSION }}"
git push
create_draft:
needs: ["linux"]
needs: ["linux", "macos"]
name: Create Draft
runs-on: ubuntu-latest
outputs:
Expand Down Expand Up @@ -75,6 +150,8 @@ jobs:
- name: Render release notes
run: |
export DEBIAN_URL="https://github.com/chevdor/tera-cli/releases/download/${{ env.RELEASE_VERSION }}/linux/tera-cli_linux_amd64.deb"
export MACOS_TGZ_URL="https://github.com/chevdor/tera-cli/releases/download/${{ env.RELEASE_VERSION }}/macos/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz"
export MACOS_BIN_URL="https://github.com/chevdor/tera-cli/releases/download/${{ env.RELEASE_VERSION }}/macos/tera-macos-${{ env.RELEASE_VERSION }}"
export CHANGELOG=$(cat changelog.md)
tera --env --env-only --template templates/release.md > RELEASE_NOTES.md
Expand All @@ -87,7 +164,7 @@ jobs:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: Tera ${{ env.RELEASE_VERSION }} (${{ env.SHORT_SHA }})
body_path: ./RELEASE_NOTES.md
draft: false
draft: true

publish-binaries:
runs-on: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions templates/env-debug.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{# you may debug using: #}
{# tera --template templates/env-debug.txt --env-only --env-key env #}

{%- for key, value in env -%}
- {{ key }}={{ value }}
{% endfor %}
14 changes: 14 additions & 0 deletions templates/formula.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% set BIN = BIN | default(value=NAME | lower) %}
{%- set HOMEPAGE = HOMEPAGE | default(value=SITE ~ "/" ~ REPO) -%}
class {{ NAME }} < Formula
desc "{{ DESCRIPTION }}"
homepage "{{ HOMEPAGE }}"
url "{{ SITE }}/{{ REPO }}/releases/download/v{{ VERSION }}/{{ ARCHIVE | default(value=BIN ~"-macos-v" ~ VERSION) }}.tar.gz"
sha256 "{{ SHA256 }}"
version "{{ VERSION }}"

def install
bin.install "{{ BIN }}"
end
end
26 changes: 21 additions & 5 deletions templates/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,31 @@ You can find the changelogs below.

Download the binary for your OS from below:
- **Linux**
- [deb package]({{ DEBIAN_URL }})

- [Debian package]({{ DEBIAN_URL }})
- **MacOS**
- [Archive]({{ MACOS_TGZ_URL }})
- [Binary]({{ MACOS_BIN_URL }})
# Install

## From source

```
cargo install --git https://github.com/chevdor/tera-cli
```

## Linux
```
URL={{ DEBIAN_URL }}
wget $URL
wget {{ DEBIAN_URL }}
dpkg -i tera-cli_linux_amd64.deb
tera --version
tera --help
```

## MacOS

```
brew tap chevdor/tera-cli https://github.com/chevdor/tera-cli
brew update
brew install tera-cli
```

{{ CHANGELOG }}
14 changes: 0 additions & 14 deletions templates/tera.rb

This file was deleted.

0 comments on commit 5655d6b

Please sign in to comment.