-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add zsv/setup-action for GHA workflows (#220)
* Add zsv/setup-action for GHA workflows * Minor updates * Update README [skip ci] * Minor cleanup
- Loading branch information
Showing
6 changed files
with
231 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: zsv/setup-action | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
paths: ['setup-action/**'] | ||
pull_request: | ||
branches: [main] | ||
paths: ['setup-action/**'] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
ci: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-13, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
setup-action | ||
- name: Set up | ||
id: setup | ||
uses: ./setup-action | ||
|
||
- name: Check output parameter [install-path] | ||
run: echo '${{ steps.setup.outputs.install-path }}' | ||
|
||
- name: Check version | ||
run: zsv version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# zsv/setup-action | ||
|
||
[![CI](https://github.com/liquidaty/zsv/actions/workflows/setup-action.yml/badge.svg?branch=main)](https://github.com/liquidaty/zsv/actions/workflows/setup-action.yml) | ||
|
||
[GitHub Action](https://docs.github.com/en/actions) to set up zsv+zsvlib. | ||
|
||
Supports Linux, macOS, and Windows runners. | ||
|
||
## Usage | ||
|
||
### Inputs | ||
|
||
| Input | Required | Default | Description | | ||
| :-------: | :------: | :------: | :------------------------- | | ||
| `version` | `false` | `latest` | Version/tag of the release | | ||
|
||
### Outputs | ||
|
||
| Output | Description | | ||
| :------------: | :------------------------------------------ | | ||
| `install-path` | Absolute path of the installation directory | | ||
|
||
Under the installation directory, the subdirectories will include: | ||
|
||
- `bin`: `zsv`/`zsv.exe` executable | ||
- `include`: header files | ||
- `lib`: `libzsv` library file | ||
|
||
### Example | ||
|
||
Set up the latest version: | ||
|
||
```yml | ||
- name: Set up zsv+zsvlib | ||
uses: liquidaty/zsv/setup-action@main | ||
``` | ||
Set up a specific version: | ||
```yml | ||
- name: Set up zsv+zsvlib | ||
uses: liquidaty/zsv/setup-action@main | ||
with: | ||
version: '0.3.9-alpha' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: zsv/setup-action | ||
description: GitHub Action to set up zsv+zsvlib | ||
|
||
branding: | ||
icon: download | ||
color: green | ||
|
||
inputs: | ||
version: | ||
description: Version/tag of the release | ||
required: false | ||
default: latest | ||
|
||
outputs: | ||
install-path: | ||
description: Absolute path of the installation directory | ||
value: ${{ steps.setup.outputs.install-path }} | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: Setup | ||
id: setup | ||
env: | ||
VERSION: '${{ inputs.version }}' | ||
shell: bash | ||
run: $GITHUB_ACTION_PATH/scripts/setup.bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
echo "[INF] Setting up zsv+zsvlib..." | ||
|
||
echo "[INF] - RUNNER_ENVIRONMENT: $RUNNER_ENVIRONMENT" | ||
echo "[INF] - RUNNER_OS: $RUNNER_OS" | ||
echo "[INF] - RUNNER_ARCH: $RUNNER_ARCH" | ||
echo "[INF] - VERSION: $VERSION" | ||
|
||
# shellcheck disable=SC2207 | ||
AVAILABLE_VERSIONS=($(git ls-remote --tags --refs https://github.com/liquidaty/zsv | cut -d '/' -f3 | sort -r | xargs)) | ||
|
||
TARGET_VERSION= | ||
if [[ $VERSION == "latest" ]]; then | ||
TARGET_VERSION="${AVAILABLE_VERSIONS[0]}" | ||
else | ||
if [[ $VERSION != "v"* ]]; then | ||
TARGET_VERSION="v$VERSION" | ||
fi | ||
|
||
echo "[INF] Validating version/tag..." | ||
IS_VALID_VERSION=false | ||
for AV in "${AVAILABLE_VERSIONS[@]}"; do | ||
if [[ $TARGET_VERSION == "$AV" ]]; then | ||
IS_VALID_VERSION=true | ||
break | ||
fi | ||
done | ||
if [[ $IS_VALID_VERSION == false ]]; then | ||
echo "[ERR] Version/tag not found! [$VERSION]" | ||
echo "[ERR] Available versions/tags are:" | ||
for AV in "${AVAILABLE_VERSIONS[@]}"; do | ||
echo "[ERR] - $AV" | ||
done | ||
exit 1 | ||
fi | ||
echo "[INF] Validated version/tag successfully!" | ||
fi | ||
|
||
TARGET_VERSION="${TARGET_VERSION:1}" | ||
|
||
TRIPLET= | ||
if [[ $RUNNER_OS == "Linux" ]]; then | ||
if [[ $RUNNER_ARCH == "X64" ]]; then | ||
TRIPLET="amd64-linux-gcc" | ||
fi | ||
elif [[ $RUNNER_OS == "macOS" ]]; then | ||
if [[ $RUNNER_ARCH == "X64" ]]; then | ||
TRIPLET="amd64-macosx-gcc" | ||
elif [[ $RUNNER_ARCH == "ARM64" ]]; then | ||
TRIPLET="arm64-macosx-gcc" | ||
fi | ||
elif [[ $RUNNER_OS == "Windows" ]]; then | ||
if [[ $RUNNER_ARCH == "X86" || $RUNNER_ARCH == "X64" ]]; then | ||
TRIPLET="amd64-windows-mingw" | ||
fi | ||
|
||
if ! which wget >/dev/null; then | ||
echo "[INF] Installing wget..." | ||
if ! choco install wget --no-progress >/dev/null; then | ||
echo "[ERR] Failed to install wget!" | ||
exit 1 | ||
fi | ||
fi | ||
fi | ||
|
||
if [[ -z $TRIPLET ]]; then | ||
echo "[ERR] Architecture/OS not supported! [$RUNNER_ARCH $RUNNER_OS]" | ||
exit 1 | ||
fi | ||
|
||
INSTALL_DIR="$RUNNER_TEMP/zsv" | ||
echo "[INF] INSTALL_DIR: $INSTALL_DIR" | ||
|
||
rm -rf "${INSTALL_DIR:?}"/{bin,include,lib} | ||
mkdir -p "$INSTALL_DIR" | ||
cd "$INSTALL_DIR" | ||
|
||
ZIP="zsv-$TARGET_VERSION-$TRIPLET.zip" | ||
URL="https://github.com/liquidaty/zsv/releases/download/v$TARGET_VERSION/$ZIP" | ||
|
||
echo "[INF] Downloading... [$URL]" | ||
if [[ ! -f $ZIP ]]; then | ||
wget --quiet "$URL" | ||
echo "[INF] Downloaded successfully!" | ||
else | ||
echo "[INF] Archive already exists! Skipping download..." | ||
fi | ||
|
||
echo "[INF] Extracting... [$ZIP]" | ||
unzip -q -o "$ZIP" | ||
echo "[INF] Extracted successfully!" | ||
|
||
INSTALL_PATH="$(realpath "$INSTALL_DIR")" | ||
echo "[INF] INSTALL_PATH: $INSTALL_PATH" | ||
|
||
echo "[INF] Setting PATH... [$INSTALL_PATH]" | ||
echo "$INSTALL_PATH/bin" >>"$GITHUB_PATH" | ||
|
||
echo "[INF] Setting output parameter... [install-path]" | ||
echo "install-path=$INSTALL_PATH" >>"$GITHUB_OUTPUT" | ||
|
||
echo "[INF] zsv+zsvlib set up successfully!" | ||
echo "[INF] --- [DONE] ---" |