From 5e23556e7b270e65773c8aa148e1ee5afc4b24b6 Mon Sep 17 00:00:00 2001 From: Azeem Sajid Date: Fri, 11 Oct 2024 18:28:12 +0500 Subject: [PATCH 1/4] Add zsv/setup-action for GHA workflows --- .github/workflows/ci.yml | 4 +- .github/workflows/setup-action.yml | 40 +++++++++ README.md | 14 ++++ setup-action/README.md | 39 +++++++++ setup-action/action.yml | 28 +++++++ setup-action/scripts/setup.bash | 127 +++++++++++++++++++++++++++++ 6 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/setup-action.yml create mode 100644 setup-action/README.md create mode 100644 setup-action/action.yml create mode 100755 setup-action/scripts/setup.bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee810f5..2ab271f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,10 @@ name: ci on: push: branches: [main] - paths-ignore: ['**.md'] + paths-ignore: ['**.md', 'setup-action/**'] pull_request: branches: [main] - paths-ignore: ['**.md'] + paths-ignore: ['**.md', 'setup-action/**'] release: types: [published] diff --git a/.github/workflows/setup-action.yml b/.github/workflows/setup-action.yml new file mode 100644 index 00000000..c67878bb --- /dev/null +++ b/.github/workflows/setup-action.yml @@ -0,0 +1,40 @@ +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 + with: + version: '0.3.9-alpha' + + - name: Check output parameter [install-path] + run: echo '${{ steps.setup.outputs.install-path }}' + + - name: Check version + run: zsv version diff --git a/README.md b/README.md index 1cc24df1..ea48026e 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,20 @@ $ cat worldcitiespop_mil.csv | docker run -i ghcr.io/liquidaty/zsv count For image details, see [Dockerfile](./Dockerfile). You may use this as a baseline for your own use cases as needed. +#### GitHub Actions + +In a GitHub Actions workflow, you can use `zsv/setup-action` to install +zsv+zsvlib: + +```yml +- name: Set up zsv+zsvlib + uses: liquidaty/zsv/setup-action@main + with: + version: 'version' +``` + +See [zsv/setup-action](./setup-action) for more details. + ### From source See [BUILD.md](BUILD.md) for more details. diff --git a/setup-action/README.md b/setup-action/README.md new file mode 100644 index 00000000..50ec093b --- /dev/null +++ b/setup-action/README.md @@ -0,0 +1,39 @@ +# 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 + +| Output | Description | +| :-------: | :------------------------- | +| `version` | 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 + +```yml +- name: Set up zsv+zsvlib + uses: liquidaty/zsv/setup-action@main + with: + version: '0.3.9-alpha' + +- name: Check version + run: zsv version +``` diff --git a/setup-action/action.yml b/setup-action/action.yml new file mode 100644 index 00000000..816ff698 --- /dev/null +++ b/setup-action/action.yml @@ -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 diff --git a/setup-action/scripts/setup.bash b/setup-action/scripts/setup.bash new file mode 100755 index 00000000..31a6d57e --- /dev/null +++ b/setup-action/scripts/setup.bash @@ -0,0 +1,127 @@ +#!/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}" +TARGET_ARCH= +TARGET_OS= +TARGET_COMPILER= + +if [[ $RUNNER_OS == "Linux" ]]; then + if [[ $RUNNER_ARCH == "X64" ]]; then + TARGET_ARCH="amd64" + TARGET_OS="linux" + TARGET_COMPILER="gcc" + fi +elif [[ $RUNNER_OS == "macOS" ]]; then + if [[ $RUNNER_ARCH == "X64" ]]; then + TARGET_ARCH="amd64" + TARGET_OS="macosx" + TARGET_COMPILER="gcc" + elif [[ $RUNNER_ARCH == "ARM64" ]]; then + TARGET_ARCH="arm64" + TARGET_OS="macosx" + TARGET_COMPILER="gcc" + fi +elif [[ $RUNNER_OS == "Windows" ]]; then + if [[ $RUNNER_ARCH == "X86" || $RUNNER_ARCH == "X64" ]]; then + TARGET_ARCH="amd64" + TARGET_OS="windows" + TARGET_COMPILER="mingw" + fi + + if ! which wget; then + echo "[INF] Installing wget..." + if ! choco install wget --no-progress >/dev/null; then + echo "[ERR] Failed to install wget!" + exit 1 + fi + fi +else + echo "[ERR] Unsupported OS! [$RUNNER_OS]" + exit 1 +fi + +if [[ -z $TARGET_ARCH ]]; then + echo "[ERR] Runner architecture not supported! [$RUNNER_ARCH]" + exit 1 +fi + +if [[ -z $TARGET_OS ]]; then + echo "[ERR] Runner OS not supported! [$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" + +TRIPLET="$TARGET_ARCH-$TARGET_OS-$TARGET_COMPILER" +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] Set up successfully!" +echo "[INF] --- [DONE] ---" From 7db8fb79a589e9e6ab1f22a82095af4e61490032 Mon Sep 17 00:00:00 2001 From: Azeem Sajid Date: Fri, 11 Oct 2024 18:41:56 +0500 Subject: [PATCH 2/4] Minor updates --- .github/workflows/setup-action.yml | 2 -- README.md | 8 +++----- setup-action/README.md | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/setup-action.yml b/.github/workflows/setup-action.yml index c67878bb..2eef95f8 100644 --- a/.github/workflows/setup-action.yml +++ b/.github/workflows/setup-action.yml @@ -30,8 +30,6 @@ jobs: - name: Set up id: setup uses: ./setup-action - with: - version: '0.3.9-alpha' - name: Check output parameter [install-path] run: echo '${{ steps.setup.outputs.install-path }}' diff --git a/README.md b/README.md index ea48026e..a8c7a690 100644 --- a/README.md +++ b/README.md @@ -235,17 +235,15 @@ baseline for your own use cases as needed. #### GitHub Actions -In a GitHub Actions workflow, you can use `zsv/setup-action` to install -zsv+zsvlib: +In a GitHub Actions workflow, you can use [`zsv/setup-action`](./setup-action) +to set up zsv+zsvlib: ```yml - name: Set up zsv+zsvlib uses: liquidaty/zsv/setup-action@main - with: - version: 'version' ``` -See [zsv/setup-action](./setup-action) for more details. +See [zsv/setup-action/README](./setup-action/README.md) for more details. ### From source diff --git a/setup-action/README.md b/setup-action/README.md index 50ec093b..d4ace05f 100644 --- a/setup-action/README.md +++ b/setup-action/README.md @@ -10,9 +10,9 @@ Supports Linux, macOS, and Windows runners. ### Inputs -| Output | Description | -| :-------: | :------------------------- | -| `version` | Version/tag of the release | +| Input | Required | Default | Description | +| :-------: | :------- | +| `version` | `false` | `latest` | Version/tag of the release | ### Outputs @@ -28,12 +28,18 @@ Under the installation directory, the subdirectories will include: ### 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' - -- name: Check version - run: zsv version ``` From 6acc548cf097cea60374902ca785e949f2b185cd Mon Sep 17 00:00:00 2001 From: Azeem Sajid Date: Fri, 11 Oct 2024 18:53:25 +0500 Subject: [PATCH 3/4] Update README [skip ci] --- setup-action/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-action/README.md b/setup-action/README.md index d4ace05f..4285ac6e 100644 --- a/setup-action/README.md +++ b/setup-action/README.md @@ -11,7 +11,7 @@ Supports Linux, macOS, and Windows runners. ### Inputs | Input | Required | Default | Description | -| :-------: | :------- | +| :-------: | :------- | :------: | :------------------------- | | `version` | `false` | `latest` | Version/tag of the release | ### Outputs From c88fa88c2f4ca4f864e6e57b2c98d67ad18acfbd Mon Sep 17 00:00:00 2001 From: Azeem Sajid Date: Fri, 11 Oct 2024 22:06:39 +0500 Subject: [PATCH 4/4] Minor cleanup --- setup-action/README.md | 2 +- setup-action/scripts/setup.bash | 111 +++++++++++++------------------- 2 files changed, 46 insertions(+), 67 deletions(-) diff --git a/setup-action/README.md b/setup-action/README.md index 4285ac6e..6d803889 100644 --- a/setup-action/README.md +++ b/setup-action/README.md @@ -11,7 +11,7 @@ Supports Linux, macOS, and Windows runners. ### Inputs | Input | Required | Default | Description | -| :-------: | :------- | :------: | :------------------------- | +| :-------: | :------: | :------: | :------------------------- | | `version` | `false` | `latest` | Version/tag of the release | ### Outputs diff --git a/setup-action/scripts/setup.bash b/setup-action/scripts/setup.bash index 31a6d57e..2187318c 100755 --- a/setup-action/scripts/setup.bash +++ b/setup-action/scripts/setup.bash @@ -14,81 +14,61 @@ AVAILABLE_VERSIONS=($(git ls-remote --tags --refs https://github.com/liquidaty/z TARGET_VERSION= if [[ $VERSION == "latest" ]]; then - TARGET_VERSION="${AVAILABLE_VERSIONS[0]}" + TARGET_VERSION="${AVAILABLE_VERSIONS[0]}" else - if [[ $VERSION != "v"* ]]; then - TARGET_VERSION="v$VERSION" + 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 - - echo "[INF] Validating version/tag..." - - IS_VALID_VERSION=false + 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 - if [[ $TARGET_VERSION == "$AV" ]]; then - IS_VALID_VERSION=true - break - fi + echo "[ERR] - $AV" 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!" + exit 1 + fi + echo "[INF] Validated version/tag successfully!" fi TARGET_VERSION="${TARGET_VERSION:1}" -TARGET_ARCH= -TARGET_OS= -TARGET_COMPILER= +TRIPLET= if [[ $RUNNER_OS == "Linux" ]]; then - if [[ $RUNNER_ARCH == "X64" ]]; then - TARGET_ARCH="amd64" - TARGET_OS="linux" - TARGET_COMPILER="gcc" - fi + if [[ $RUNNER_ARCH == "X64" ]]; then + TRIPLET="amd64-linux-gcc" + fi elif [[ $RUNNER_OS == "macOS" ]]; then - if [[ $RUNNER_ARCH == "X64" ]]; then - TARGET_ARCH="amd64" - TARGET_OS="macosx" - TARGET_COMPILER="gcc" - elif [[ $RUNNER_ARCH == "ARM64" ]]; then - TARGET_ARCH="arm64" - TARGET_OS="macosx" - TARGET_COMPILER="gcc" - fi + 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 - TARGET_ARCH="amd64" - TARGET_OS="windows" - TARGET_COMPILER="mingw" + 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 - - if ! which wget; then - echo "[INF] Installing wget..." - if ! choco install wget --no-progress >/dev/null; then - echo "[ERR] Failed to install wget!" - exit 1 - fi - fi -else - echo "[ERR] Unsupported OS! [$RUNNER_OS]" - exit 1 + fi fi -if [[ -z $TARGET_ARCH ]]; then - echo "[ERR] Runner architecture not supported! [$RUNNER_ARCH]" - exit 1 -fi - -if [[ -z $TARGET_OS ]]; then - echo "[ERR] Runner OS not supported! [$RUNNER_OS]" - exit 1 +if [[ -z $TRIPLET ]]; then + echo "[ERR] Architecture/OS not supported! [$RUNNER_ARCH $RUNNER_OS]" + exit 1 fi INSTALL_DIR="$RUNNER_TEMP/zsv" @@ -98,16 +78,15 @@ rm -rf "${INSTALL_DIR:?}"/{bin,include,lib} mkdir -p "$INSTALL_DIR" cd "$INSTALL_DIR" -TRIPLET="$TARGET_ARCH-$TARGET_OS-$TARGET_COMPILER" 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!" + wget --quiet "$URL" + echo "[INF] Downloaded successfully!" else - echo "[INF] Archive already exists! Skipping download..." + echo "[INF] Archive already exists! Skipping download..." fi echo "[INF] Extracting... [$ZIP]" @@ -123,5 +102,5 @@ echo "$INSTALL_PATH/bin" >>"$GITHUB_PATH" echo "[INF] Setting output parameter... [install-path]" echo "install-path=$INSTALL_PATH" >>"$GITHUB_OUTPUT" -echo "[INF] Set up successfully!" +echo "[INF] zsv+zsvlib set up successfully!" echo "[INF] --- [DONE] ---"