Skip to content

Actions #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
[push, pull_request]

env:
CARGO_TERM_COLOR: always

jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]

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

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy
override: true
- uses: Swatinem/rust-cache@v1
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run tests
run: cargo test --verbose
- name: Annotate commit with clippy warnings
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release

on:
push:
tags: ["[0-9]+.[0-9]+.[0-9]+*"]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_TERM_COLOR: always

jobs:
linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install cargo-deb
run: cargo install cargo-deb
- name: Install cargo-generate-rpm
run: cargo install cargo-generate-rpm
- name: Install cargo-appimage
run: cargo install cargo-appimage
- name: Test
run: cargo test --release
- name: Build .deb
run: cargo deb --verbose
- name: Upload .deb package
run: |
cp ./target/debian/*.deb ./commit_${GITHUB_REF##*/}_amd64.deb
./.github/workflows/upload_asset.sh \
"alt-art/commit" ./commit_${GITHUB_REF##*/}_amd64.deb $GITHUB_TOKEN
- name: Build .rpm
run: cargo generate-rpm --verbose
- name: Upload .rpm package
run: |
cp ./target/generate-rpm/rpm/*.rpm ./commit_${GITHUB_REF##*/}_x86_64.rpm
./.github/workflows/upload_asset.sh \
"alt-art/commit" ./commit_${GITHUB_REF##*/}_x86_64.rpm $GITHUB_TOKEN
- name: Build .AppImage
run: cargo appimage --verbose
- name: Upload .AppImage
run: |
cp ./*.AppImage ./commit_${GITHUB_REF##*/}_x86_64.AppImage
./.github/workflows/upload_asset.sh \
"alt-art/commit" ./commit_${GITHUB_REF##*/}_x86_64.AppImage $GITHUB_TOKEN

windows:
runs-on: windows-latest

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v2
- name: Test
run: cargo test --release
- name: Build
run: cargo build --release
- name: Upload portable executable
run: |
cp ./target/release/commit.exe ./commit-${GITHUB_REF##*/}-portable.exe
./.github/workflows/upload_asset.sh \
"alt-art/commit" ./commit-${GITHUB_REF##*/}-portable.exe $GITHUB_TOKEN
102 changes: 102 additions & 0 deletions .github/workflows/upload_asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
#
# Author: Christian Duerr
# License: Apache-2.0
# https://github.com/alacritty/alacritty/blob/master/.github/workflows/upload_asset.sh
#
#
# This script accepts the following parameters:
#
# * "owner/repo"
# * file_path
# * token
#
# Script to upload a release asset
#
# Example:
#
# upload_asset.sh "alt-art/lyrs" ./build.zip $GITHUB_TOKEN

repo=$1
file_path=$2
file_name=${file_path##*/}
token=$3

echo "Starting asset upload from $file_name to $repo."
# Define variables.
TAG="$(git describe --tags --abbrev=0)"
if [ -z "$TAG" ]; then
printf "\e[31mError: Unable to find git tag\e[0m\n"
exit 1
fi
echo "Git tag: $TAG"
GH_API="https://api.github.com"
GH_REPO="$GH_API/repos/$repo"
AUTH="Authorization: Bearer $token"

# Validate token.
curl -o /dev/null -sH "$AUTH" "$GH_REPO" || { echo "Error: Invalid repo, token or network issue!"; exit 1; }

echo "Checking for existing release..."
upload_url=$(\
curl \
-H "$AUTH" \
"$GH_REPO/releases" \
2> /dev/null \
| grep -E "(upload_url|tag_name)" \
| paste - - \
| grep -e "tag_name\": \"$TAG\"" \
| head -n 1 \
| sed 's/.*\(https.*assets\).*/\1/' \
)

# Create a new release if we didn't find one for this tag.
if [ -z "$upload_url" ]; then
echo "No release found."
echo "Creating new release..."

# Create new release.
response=$(
curl -f \
-X POST \
-H "$AUTH" \
-d "{\"tag_name\":\"$TAG\",\"draft\":true}" \
"$GH_REPO/releases" \
2> /dev/null\
)

# Abort if the release could not be created.
if [ $? -ne 0 ]; then
printf "\e[31mError: Unable to create new release.\e[0m\n"
exit 1;
fi

# Extract upload URL from new release.
upload_url=$(\
echo "$response" \
| grep "upload_url" \
| sed 's/.*: "\(.*\){.*/\1/' \
)
fi

if [ -z "$upload_url" ]; then
printf "\e[31mError: Unable to find release upload url.\e[0m\n"
exit 2
fi

# Upload asset

echo "Uploading asset $file_name to $TAG..."
curl -f \
-X POST \
-H "$AUTH" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$file_path" \
"$upload_url?name=$file_name" \
&> /dev/null \
|| { \
printf "\e[31mError: Unable to upload asset.\e[0m\n" \
&& exit 3; \
}

printf "\e[32mSuccess\e[0m\n"