Skip to content

Commit

Permalink
ci: reuse workflows
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <troian.ap@gmail.com>
  • Loading branch information
troian committed Oct 11, 2024
1 parent d580137 commit 3b0cd31
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 44 deletions.
29 changes: 29 additions & 0 deletions .github/actions/setup-ubuntu/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: setup-ubuntu
runs:
using: 'composite'
steps:
- name: Install dependencies
# Shell must explicitly specify the shell for each step. https://github.com/orgs/community/discussions/18597
shell: bash
run: sudo apt install -y make direnv unzip lz4 wget curl npm jq pv coreutils
- name: Install git-cliff
shell: bash
uses: baptiste0928/cargo-install@v3
with:
crate: git-cliff
- name: Detect required Go version
shell: bash
run: |
toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//')
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- uses: actions/setup-go@v5
shell: bash
with:
go-version: "${{ env.GOVERSION }}"
check-latest: true
- name: set environment
shell: bash
uses: HatsuneMiku3939/direnv-action@v1
with:
masks: ''
4 changes: 4 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
- run: git fetch --prune --unshallow
- name: Install dependencies
run: sudo apt install -y make direnv unzip lz4 wget curl npm jq pv coreutils
- name: Install git-cliff
uses: baptiste0928/cargo-install@v3
with:
crate: git-cliff
- name: Detect required Go version
run: |
toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//')
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ jobs:
run: |
brew install bash direnv pv lz4 git-cliff
sudo chsh -s /usr/local/bin/bash
- name: Install git-cliff
uses: baptiste0928/cargo-install@v3
with:
crate: git-cliff
- name: Hook direnv to bash
run: echo 'eval "$(direnv hook bash)"' >> $HOME/.bashrc
- uses: actions/checkout@v4
Expand All @@ -43,6 +39,7 @@ jobs:
direnv allow
direnv export gha >> "$GITHUB_ENV"
- run: make bins

build-bins:
runs-on: ubuntu-latest
steps:
Expand All @@ -64,8 +61,6 @@ jobs:
check-latest: true
- name: set environment
uses: HatsuneMiku3939/direnv-action@v1
with:
masks: ''
- run: make bins
- run: make docker-image

Expand Down
98 changes: 98 additions & 0 deletions script/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ SEMVER=$SCRIPT_DIR/semver.sh

gomod="$SCRIPT_DIR/../go.mod"

macos_deps=(
"bash"
"direnv"
"pv"
"lz4"
"git-cliff"
)

debian_deps=(
"make"
"build-essentials"
"direnv"
"unzip"
"wget"
"curl"
"npm"
"jq"
"coreutils"
)

is_command() {
command -v "$1" >/dev/null
}

function get_gotoolchain() {
local gotoolchain
local goversion
Expand Down Expand Up @@ -117,6 +141,80 @@ function replace_import_path() {
replace_paths "./go/go.mod" "$curr_module_name" "$new_module_name"
}

function install_gha_deps() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Detected Darwin based system"

if ! is_command brew; then
echo "homebrew is not installed. visit https://brew.sh"
exit 1
fi

local tools

if ! is_command make || [[ $(make --version | head -1 | cut -d" " -f3 | cut -d"." -f1) -lt 4 ]]; then
tools="$tools make"
fi

# shellcheck disable=SC2068
for dep in ${macos_deps[@]}; do
echo -n "detecting $dep ..."
status="(installed)"
if ! brew list "$dep" >/dev/null 2>&1; then
tools="$tools $dep"
status="(not installed)"
fi

echo " $status"
done

if [[ "$tools" != "" ]]; then
# don't put quotes around $tools!
# shellcheck disable=SC2086
brew install $tools
else
echo "All requirements already met. Nothing to install"
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
if is_command dpkg; then
echo "Detected Debian based system"
local tools

# shellcheck disable=SC2068
for dep in ${debian_deps[@]}; do
echo -n "detecting $dep ..."
status="(installed)"
if ! dpkg -l "$dep"; then
tools="$tools $dep"
status="(not installed)"
fi
echo " $status"
done

cmd="apt-get"

if is_command sudo; then
cmd="sudo $cmd"
fi

if [[ "$tools" != "" ]]; then
$cmd update
# don't put quotes around $tools!
# shellcheck disable=SC2086
(
set -x
$cmd install -y $tools
)
else
echo "All requirements already met. Nothing to install"
fi
fi
else
echo "Unsupported OS $OSTYPE"
exit 1
fi
}

case "$1" in
gotoolchain)
get_gotoolchain
Expand Down
3 changes: 1 addition & 2 deletions tests/upgrade/test-config-gha.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"chain-id": "localakash",
"validators": [
".akash0",
".akash1",
".akash2"
".akash1"
],
"work": {
"home": ".akash0",
Expand Down
Loading

0 comments on commit 3b0cd31

Please sign in to comment.