CI: Add initial release workflow

This commit is contained in:
alstjr7375 2021-03-11 13:37:15 +09:00 committed by Danilo Bargen
commit 2007aa0c32
2 changed files with 134 additions and 0 deletions

97
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,97 @@
on:
push:
tags:
- "v*" # push events to matching v*, i.e. v1.0, v20.15.10
jobs:
completions-upload:
runs-on: ubuntu-latest
strategy:
matrix:
target: ["bash", "fish", "zsh"]
steps:
- uses: actions/checkout@v2
- name: Upload
if: startsWith(github.ref, 'refs/tags/')
run: |
sudo apt update && sudo apt install -y jq
source ./upload-asset.sh
upload_release_file ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ matrix.target }}_tealdeer completions_${{ matrix.target }}
license-upload:
runs-on: ubuntu-latest
strategy:
matrix:
target: ["MIT", "APACHE"]
steps:
- uses: actions/checkout@v2
- name: Upload
if: startsWith(github.ref, 'refs/tags/')
run: |
sudo apt update && sudo apt install -y jq
source ./upload-asset.sh
upload_release_file ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} LICENSE-${{ matrix.target }} LICENSE-${{ matrix.target }}
build-linux:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- arch: "x86_64"
libc: "musl"
- arch: "i686"
libc: "musl"
- arch: "armv7"
libc: "musleabihf"
- arch: "arm"
libc: "musleabi"
- arch: "arm"
libc: "musleabihf"
steps:
- uses: actions/checkout@v2
- name: Docker Pull
run: docker pull messense/rust-musl-cross:${{ matrix.arch }}-${{ matrix.libc }}
- name: Build with Docker
run: docker run --rm -i -v "$(pwd)":/home/rust/src messense/rust-musl-cross:${{ matrix.arch }}-${{ matrix.libc }} cargo build --release
- name: Stripping
run: docker run --rm -i -v "$(pwd)":/home/rust/src messense/rust-musl-cross:${{ matrix.arch }}-${{ matrix.libc }} musl-strip -s /home/rust/src/target/${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}/release/tldr
- uses: actions/upload-artifact@v2
with:
name: "tldr-linux-${{ matrix.arch }}-${{ matrix.libc }}"
path: "target/${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}/release/tldr"
build-darwin:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target x86_64-apple-darwin
- uses: actions/upload-artifact@v2
with:
name: "tldr-apple-darwin-x86_64"
path: "target/x86_64-apple-darwin/release/tldr"
release-upload:
needs:
- build-linux
- build-darwin
runs-on: ubuntu-latest
strategy:
matrix:
target: ["linux-x86_64-musl", "linux-i686-musl", "linux-armv7-musleabihf", "linux-arm-musleabi", "linux-arm-musleabihf", "apple-darwin-x86_64"]
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
- name: Upload
if: startsWith(github.ref, 'refs/tags/')
run: |
sudo apt update && sudo apt install -y jq
source ./upload-asset.sh
upload_release_file ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} tldr-${{ matrix.target }}/tldr tldr-${{ matrix.target }}

37
upload-asset.sh Normal file
View file

@ -0,0 +1,37 @@
#! /bin/bash
# https://gist.github.com/schell/2fe896953b6728cc3c5d8d5f9f3a17a3
# requires curl and jq on PATH: https://stedolan.github.io/jq/
# upload a release file.
# this must be called only after a successful create_release, as create_release saves
# the json response in release.json.
# token: github api user token
# repo: github username/reponame
# file: path to the asset file to upload
# name: name to use for the uploaded asset
upload_release_file() {
token=$1
repo=$2
file=$3
name=$4
url=`curl --silent "https://api.github.com/repos/${repo}/releases/latest" | jq -r .upload_url | cut -d{ -f'1'`
command="\
curl -s -o upload.json -w '%{http_code}' \
--request POST \
--header 'authorization: Bearer ${token}' \
--header 'Content-Type: application/octet-stream' \
--data-binary @\"${file}\"
${url}?name=${name}"
http_code=`eval $command`
if [ $http_code == "201" ]; then
echo "asset $name uploaded:"
jq -r .browser_download_url upload.json
else
echo "upload failed with code '$http_code':"
cat upload.json
echo "command:"
echo $command
return 1
fi
}