Skip to content

Commit

Permalink
Updating CI/CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
edmocosta committed Jun 11, 2024
1 parent a7040df commit 8e35e79
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 134 deletions.
141 changes: 78 additions & 63 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,92 +1,107 @@
name: CD
name: Release
on:
push:
tags:
- "v*.*.*"
jobs:
publish:
name: Publishing for ${{ matrix.os }}
build-release:
runs-on: ${{ matrix.os }}
permissions: write-all
strategy:
fail-fast: false
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
rust: [ stable ]
include:
# Linux
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
archive: tar.gz
archive-cmd: tar czf
sha-cmd: sha256sum
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
archive: tar.gz
archive-cmd: tar czf
sha-cmd: sha256sum
- os: ubuntu-latest
target: arm-unknown-linux-musleabihf
archive: tar.gz
archive-cmd: tar czf
sha-cmd: sha256sum
- os: ubuntu-latest
target: loongarch64-unknown-linux-gnu
archive: tar.gz
archive-cmd: tar czf
sha-cmd: sha256sum

# MacOS
- os: macos-latest
artifact_prefix: macos
target: x86_64-apple-darwin
binary_postfix: ""
- os: ubuntu-latest
artifact_prefix: linux
target: x86_64-unknown-linux-gnu
binary_postfix: ""
archive: zip
archive-cmd: zip -r
sha-cmd: shasum -a 256
- os: macos-latest
target: aarch64-apple-darwin
archive: zip
archive-cmd: zip -r
sha-cmd: shasum -a 256

# Windows
- os: windows-latest
artifact_prefix: windows
target: x86_64-pc-windows-msvc
binary_postfix: ".exe"
archive: zip
archive-cmd: 7z a
sha-cmd: sha256sum

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Installing Rust toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Installing needed macOS dependencies
if: matrix.os == 'macos-latest'
run: brew install [email protected]
- name: Installing needed Ubuntu dependencies
target: ${{ matrix.target }}
toolchain: stable

- uses: Swatinem/rust-cache@v2

- name: Build for Linux
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
- name: Checking out sources
uses: actions/checkout@v1
- name: Running cargo build
uses: actions-rs/cargo@v1
with:
command: build
toolchain: ${{ matrix.rust }}
args: --release --target ${{ matrix.target }}
cargo install cross --git https://github.com/cross-rs/cross
cross build --release --target ${{ matrix.target }}
- name: Build for Darwin and Windows
if: matrix.os == 'macos-latest' || matrix.os == 'windows-latest'
run: cargo build --release --target ${{ matrix.target }}

- name: Packaging final binary
- name: Packaging final binaries
shell: bash
run: |
cd target/${{ matrix.target }}/release
BINARY_NAME=tuistash${{ matrix.binary_postfix }}
strip $BINARY_NAME
RELEASE_NAME=tuistash-${{ matrix.artifact_prefix }}
tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME
if [[ ${{ runner.os }} == 'Windows' ]]; then
certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
src=$(pwd)
stage=$(mktemp -d)
ver=${GITHUB_REF#refs/tags/}
asset_name="tuistash-$ver-${{ matrix.target }}.${{ matrix.archive }}"
ASSET_PATH="$src/$asset_name"
CHECKSUM_PATH="$ASSET_PATH.sha256"
cp target/${{ matrix.target }}/release/tuistash $stage/
cd $stage
${{ matrix.archive-cmd }} $ASSET_PATH *
cd $src
${{ matrix.sha-cmd }} $asset_name > $CHECKSUM_PATH
if [ "$RUNNER_OS" == "Windows" ]; then
echo "ASSET_PATH=$(cygpath -m $ASSET_PATH)" >> $GITHUB_ENV
echo "CHECKSUM_PATH=$(cygpath -m $CHECKSUM_PATH)" >> $GITHUB_ENV
else
shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256
echo "ASSET_PATH=$ASSET_PATH" >> $GITHUB_ENV
echo "CHECKSUM_PATH=$CHECKSUM_PATH" >> $GITHUB_ENV
fi
- name: Releasing assets
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
fail_on_unmatched_files: true
files: |
target/${{ matrix.target }}/release/tuistash-${{ matrix.artifact_prefix }}.tar.gz
target/${{ matrix.target }}/release/tuistash-${{ matrix.artifact_prefix }}.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version
id: extract-version
run: |
printf "::set-output name=%s::%s\n" tag-name "${GITHUB_REF#refs/tags/}"
- name: Bump Homebrew formula
uses: mislav/bump-homebrew-formula-action@v2
if: "matrix.os == 'macos-latest' && !contains(github.ref, '-')" # skip pre-releases
with:
formula-name: tuistash
formula-path: Formula/tuistash.rb
homebrew-tap: edmocosta/homebrew-tap
base-branch: main
download-url: https://github.com/edmocosta/tuistash/releases/download/${{ steps.extract-version.outputs.tag-name }}/tuistash-macos.tar.gz
commit-message: |
{{formulaName}} {{version}}
${{ env.ASSET_PATH }}
${{ env.CHECKSUM_PATH }}
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95 changes: 25 additions & 70 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,89 +1,44 @@
on:
pull_request:
push:
branches: main
branches:
- main

name: CI
jobs:
# Skip based on commit message `[skip ci]`
# Source https://gist.github.com/ybiquitous/c80f15c18319c63cae8447a3be341267
prepare:
runs-on: ubuntu-latest
if: |
!contains(format('{0} {1} {2}', github.event.head_commit.message, github.event.pull_request.title, github.event.pull_request.body), '[skip ci]')
steps:
- run: |
cat <<'MESSAGE'
github.event_name: ${{ toJson(github.event_name) }}
github.event:
${{ toJson(github.event) }}
MESSAGE
check:
name: Check
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: actions-rs/cargo@v1
with:
command: check

# Commented for now (no tests implemented yet)
# test:
# name: Test Suite
# runs-on: ubuntu-latest
# needs: prepare
# steps:
# - uses: actions/checkout@master
# - uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
# profile: minimal
# override: true
# - run: sudo apt-get install -y -qq libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
# - uses: Swatinem/rust-cache@v1
# - uses: actions-rs/cargo@v1
# with:
# command: test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: stable
profile: minimal
override: true
components: rustfmt
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
profile: minimal
override: true
components: clippy
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets --all-features -- -D warnings

test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macOS-latest ]
rust: [ stable, beta, nightly ]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
command: clippy
args: -- -D warnings
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- run: cargo test --all-features
2 changes: 1 addition & 1 deletion .github/workflows/homebrew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
formula-path: Formula/tuistash.rb
homebrew-tap: edmocosta/homebrew-tap
tag-name: ${{ github.event.inputs.tag-name }}
download-url: https://github.com/edmocosta/tuistash/releases/download/${{ github.event.inputs.tag-name }}/tuistash-macos.tar.gz
download-url: https://github.com/edmocosta/tuistash/releases/download/${{ github.event.inputs.tag-name }}/tuistash-${{ github.event.inputs.tag-name }}-x86_64-apple-darwin.zip
commit-message: |
{{formulaName}} {{version}}
env:
Expand Down

0 comments on commit 8e35e79

Please sign in to comment.