Skip to content

Commit 5655d6b

Browse files
authored
ci: macos binaries and homebrew (#5)
1 parent 5085186 commit 5655d6b

5 files changed

Lines changed: 120 additions & 21 deletions

File tree

.github/workflows/release.yml

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,83 @@ jobs:
3636
name: linux
3737
path: "tera-cli_linux_amd64.deb"
3838

39+
macos:
40+
env:
41+
TARGET_DIR: target/release
42+
43+
runs-on: macos-latest
44+
steps:
45+
- uses: actions/checkout@v2
46+
- name: Get Release Version
47+
run: |
48+
echo GITHUB_REF=$GITHUB_REF
49+
RELEASE_VERSION=${GITHUB_REF#refs/*/}
50+
RAW_VERSION=${RELEASE_VERSION:1}
51+
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
52+
echo "RAW_VERSION=$RAW_VERSION" >> $GITHUB_ENV
53+
echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
54+
55+
- name: Install latest nightly
56+
uses: actions-rs/toolchain@v1
57+
with:
58+
toolchain: nightly
59+
override: true
60+
components: rustfmt, clippy
61+
62+
- name: Check tooling
63+
shell: bash
64+
run: |
65+
tar --version
66+
shasum --version
67+
68+
- name: Build MacOS binary
69+
shell: bash
70+
run: |
71+
cargo build --release
72+
# echo "${{ github.workspace }}/${{ env.TARGET_DIR }}" >> $GITHUB_PATH
73+
cp "${{ env.TARGET_DIR }}/tera" /usr/local/bin
74+
75+
- name: Compress & sha256
76+
run: |
77+
tar -czf ${{ env.TARGET_DIR }}/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz -C ${{ env.TARGET_DIR }} tera
78+
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)
79+
echo SHA256: $SHA256
80+
echo "SHA256=$SHA256" >> $GITHUB_ENV
81+
82+
- name: Upload artifacts
83+
uses: actions/upload-artifact@v2
84+
with:
85+
name: macos
86+
path: |
87+
${{ env.TARGET_DIR }}/tera
88+
${{ env.TARGET_DIR }}/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz
89+
${{ env.TARGET_DIR }}/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz.sha256
90+
91+
# We do that before checking out master (in case we were not in master already)
92+
- name: Prepare new Formula
93+
env:
94+
NAME: Tera
95+
DESCRIPTION: "A command line utility written in Rust to render templates using the tera templating engine"
96+
SITE: https://github.com
97+
REPO: chevdor/tera-cli
98+
SHA256: ${{env.SHA256}}
99+
VERSION: ${{env.RAW_VERSION}}
100+
run: |
101+
tera --version
102+
tera --template templates/formula.rb --env-only > $HOME/tera.rb
103+
cat $HOME/tera.rb
104+
105+
- name: Update Homebrew Formula
106+
if: github.ref == 'refs/heads/master'
107+
run: |
108+
cp -f $HOME/tera.rb Formula/tera.rb
109+
git config --global user.name 'TeraBot'
110+
git config --global user.email 'chevdor@users.noreply.github.com'
111+
git commit Formula/tera.rb -m "build: new homebrew formula for ${{ env.RELEASE_VERSION }}"
112+
git push
113+
39114
create_draft:
40-
needs: ["linux"]
115+
needs: ["linux", "macos"]
41116
name: Create Draft
42117
runs-on: ubuntu-latest
43118
outputs:
@@ -75,6 +150,8 @@ jobs:
75150
- name: Render release notes
76151
run: |
77152
export DEBIAN_URL="https://github.com/chevdor/tera-cli/releases/download/${{ env.RELEASE_VERSION }}/linux/tera-cli_linux_amd64.deb"
153+
export MACOS_TGZ_URL="https://github.com/chevdor/tera-cli/releases/download/${{ env.RELEASE_VERSION }}/macos/tera-macos-${{ env.RELEASE_VERSION }}.tar.gz"
154+
export MACOS_BIN_URL="https://github.com/chevdor/tera-cli/releases/download/${{ env.RELEASE_VERSION }}/macos/tera-macos-${{ env.RELEASE_VERSION }}"
78155
export CHANGELOG=$(cat changelog.md)
79156
tera --env --env-only --template templates/release.md > RELEASE_NOTES.md
80157
@@ -87,7 +164,7 @@ jobs:
87164
tag_name: ${{ env.RELEASE_VERSION }}
88165
release_name: Tera ${{ env.RELEASE_VERSION }} (${{ env.SHORT_SHA }})
89166
body_path: ./RELEASE_NOTES.md
90-
draft: false
167+
draft: true
91168

92169
publish-binaries:
93170
runs-on: ubuntu-latest

templates/env-debug.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{# you may debug using: #}
2+
{# tera --template templates/env-debug.txt --env-only --env-key env #}
3+
4+
{%- for key, value in env -%}
5+
- {{ key }}={{ value }}
6+
{% endfor %}

templates/formula.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% set BIN = BIN | default(value=NAME | lower) %}
2+
{%- set HOMEPAGE = HOMEPAGE | default(value=SITE ~ "/" ~ REPO) -%}
3+
4+
class {{ NAME }} < Formula
5+
desc "{{ DESCRIPTION }}"
6+
homepage "{{ HOMEPAGE }}"
7+
url "{{ SITE }}/{{ REPO }}/releases/download/v{{ VERSION }}/{{ ARCHIVE | default(value=BIN ~"-macos-v" ~ VERSION) }}.tar.gz"
8+
sha256 "{{ SHA256 }}"
9+
version "{{ VERSION }}"
10+
11+
def install
12+
bin.install "{{ BIN }}"
13+
end
14+
end

templates/release.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,31 @@ You can find the changelogs below.
66

77
Download the binary for your OS from below:
88
- **Linux**
9-
- [deb package]({{ DEBIAN_URL }})
10-
9+
- [Debian package]({{ DEBIAN_URL }})
10+
- **MacOS**
11+
- [Archive]({{ MACOS_TGZ_URL }})
12+
- [Binary]({{ MACOS_BIN_URL }})
1113
# Install
1214

15+
## From source
16+
17+
```
18+
cargo install --git https://github.com/chevdor/tera-cli
19+
```
20+
21+
## Linux
1322
```
14-
URL={{ DEBIAN_URL }}
15-
wget $URL
23+
wget {{ DEBIAN_URL }}
1624
dpkg -i tera-cli_linux_amd64.deb
17-
tera --version
25+
tera --help
26+
```
27+
28+
## MacOS
29+
30+
```
31+
brew tap chevdor/tera-cli https://github.com/chevdor/tera-cli
32+
brew update
33+
brew install tera-cli
1834
```
1935

2036
{{ CHANGELOG }}

templates/tera.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)