Skip to content

Commit d0cfef7

Browse files
authored
add initial vexctl github action (#1)
Signed-off-by: cpanato <[email protected]>
1 parent 5e3ac93 commit d0cfef7

File tree

4 files changed

+328
-1
lines changed

4 files changed

+328
-1
lines changed

.github/dependabot.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright 2023 The OpenVEX Authors
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
---
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "daily"
12+
open-pull-requests-limit: 10
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#
2+
# Copyright 2023 The OpenVEX Authors
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
name: test-vexctl-action
7+
8+
on:
9+
pull_request:
10+
push:
11+
branches:
12+
- 'main'
13+
14+
jobs:
15+
16+
test_vexctl_action:
17+
strategy:
18+
matrix:
19+
os:
20+
- macos-latest
21+
- ubuntu-latest
22+
- windows-latest
23+
runs-on: ${{ matrix.os }}
24+
permissions: {}
25+
name: Install vexctl and test presence in path
26+
steps:
27+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
28+
- name: Install vexctl
29+
uses: ./
30+
- name: Check install!
31+
run: vexctl version
32+
- name: Check root directory
33+
run: |
34+
if [[ $(git diff --stat) != '' ]]; then
35+
echo 'should be clean'
36+
exit 1
37+
else
38+
exit 0
39+
fi
40+
shell: bash
41+
42+
test_vexctl_action_custom_dir_root:
43+
runs-on: ubuntu-latest
44+
permissions: {}
45+
name: Install Custom vexctl and test presence in path with custom root dir
46+
steps:
47+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
48+
- name: Install vexctl
49+
uses: ./
50+
with:
51+
install-dir: /usr/bin
52+
use-sudo: true
53+
- name: Check install!
54+
run: vexctl version
55+
- name: Check install dir!
56+
run: |
57+
[[ $(dirname "$(which vexctl)") == /usr/bin ]]
58+
shell: bash
59+
- name: Check root directory
60+
run: |
61+
[[ -z $(git diff --stat) ]]
62+
shell: bash
63+
64+
test_vexctl_action_custom_dir:
65+
strategy:
66+
matrix:
67+
os:
68+
- macos-latest
69+
- ubuntu-latest
70+
- windows-latest
71+
runs-on: ${{ matrix.os }}
72+
permissions: {}
73+
name: Install Custom path vexctl and test presence in path
74+
steps:
75+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
76+
- name: Install vexctl
77+
uses: ./
78+
with:
79+
install-dir: "$HOME/.vexctltest"
80+
- name: Check install!
81+
run: vexctl version
82+
- name: Check install dir!
83+
run: |
84+
[[ $(dirname "$(which vexctl)") == "$HOME/.vexctltest" ]]
85+
shell: bash
86+
- name: Check root directory
87+
run: |
88+
[[ -z $(git diff --stat) ]]
89+
shell: bash
90+
91+
test_vexctl_action_wrong:
92+
strategy:
93+
matrix:
94+
os:
95+
- macos-latest
96+
- ubuntu-latest
97+
- windows-latest
98+
runs-on: ${{ matrix.os }}
99+
permissions: {}
100+
name: Try to install a wrong vexctl
101+
steps:
102+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
103+
- name: Install vexctl
104+
uses: ./
105+
with:
106+
vexctl-release: 'honk'
107+
continue-on-error: true

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1-
# setup-vexctl
1+
# setup-vexctl GitHub Action
2+
3+
This action enables you to install [vexctl](https://github.com/openvex/vexctl)
4+
5+
## Usage
6+
7+
This action currently supports GitHub-provided Linux, macOS and Windows runners (self-hosted runners may not work).
8+
9+
Add the following entry to your Github workflow YAML file:
10+
11+
```yaml
12+
uses: openvex/setup-vexctl@main
13+
with:
14+
vexctl-release: '0.2.5' # optional
15+
```
16+
17+
Example using a pinned version:
18+
19+
```yaml
20+
jobs:
21+
test_vexctl_action:
22+
runs-on: ubuntu-latest
23+
24+
permissions: {}
25+
26+
name: Install vexctl and test presence in path
27+
steps:
28+
- name: Install vexctl
29+
uses: openvex/setup-vexctl@main
30+
with:
31+
vexctl-release: '0.2.5' # optional
32+
- name: Check install!
33+
run: vexctl version
34+
```
35+
36+
Example using the default version:
37+
38+
```yaml
39+
jobs:
40+
test_vexctl_action:
41+
runs-on: ubuntu-latest
42+
43+
permissions: {}
44+
45+
name: Install vexctl and test presence in path
46+
steps:
47+
- name: Install vexctl
48+
uses: openvex/setup-vexctl@main
49+
- name: Check install!
50+
run: vexctl version
51+
```
52+
53+
### Optional Inputs
54+
55+
The following optional inputs:
56+
57+
| Input | Description |
58+
| --- | --- |
59+
| `vexctl-release` | `vexctl` version to use instead of the default. |
60+
| `install-dir` | directory to place the `vexctl` binary into instead of the default (`$HOME/.vexctl`). |
61+
| `use-sudo` | set to `true` if `install-dir` location requires sudo privs. Defaults to false. |

action.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#
2+
# Copyright 2023 The OpenVEX Authors
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
name: setup-vexctl
7+
author: The OpenVEX Authors
8+
description: 'Installs vexctl and includes it in your path'
9+
branding:
10+
icon: 'package'
11+
color: 'blue'
12+
# This is pinned to the last major release, we have to bump it for each action version.
13+
inputs:
14+
vexctl-release:
15+
description: 'vexctl release version to be installed'
16+
required: false
17+
default: '0.2.5'
18+
install-dir:
19+
description: 'Where to install the vexctl binary'
20+
required: false
21+
default: '$HOME/.vexctl'
22+
use-sudo:
23+
description: 'set to true if install-dir location requires sudo privs'
24+
required: false
25+
default: 'false'
26+
runs:
27+
using: "composite"
28+
steps:
29+
- uses: sigstore/cosign-installer@1fc5bd396d372bee37d608f955b336615edf79c8 # v3.2.0
30+
with:
31+
install-dir: ${{ inputs.install-dir }}
32+
use-sudo: ${{ inputs.use-sudo }}
33+
- shell: bash
34+
run: |
35+
#!/bin/bash
36+
# vexctl install script
37+
shopt -s expand_aliases
38+
if [ -z "$NO_COLOR" ]; then
39+
alias log_info="echo -e \"\033[1;32mINFO\033[0m:\""
40+
alias log_error="echo -e \"\033[1;31mERROR\033[0m:\""
41+
else
42+
alias log_info="echo \"INFO:\""
43+
alias log_error="echo \"ERROR:\""
44+
fi
45+
set -e
46+
47+
mkdir -p ${{ inputs.install-dir }}
48+
49+
trap "popd >/dev/null" EXIT
50+
51+
pushd ${{ inputs.install-dir }} > /dev/null
52+
vexctl_executable_name='vexctl'
53+
case ${{ runner.os }} in
54+
Linux)
55+
case ${{ runner.arch }} in
56+
X64)
57+
desired_vexctl_filename='vexctl-linux-amd64'
58+
;;
59+
60+
ARM)
61+
desired_vexctl_filename='vexctl-linux-arm'
62+
;;
63+
64+
ARM64)
65+
desired_vexctl_filename='vexctl-linux-arm64'
66+
;;
67+
68+
*)
69+
log_error "unsupported architecture $arch"
70+
exit 1
71+
;;
72+
esac
73+
;;
74+
75+
macOS)
76+
case ${{ runner.arch }} in
77+
X64)
78+
desired_vexctl_filename='vexctl-darwin-amd64'
79+
;;
80+
81+
ARM64)
82+
desired_vexctl_filename='vexctl-darwin-arm64'
83+
;;
84+
85+
*)
86+
log_error "unsupported architecture $arch"
87+
exit 1
88+
;;
89+
esac
90+
;;
91+
92+
Windows)
93+
case ${{ runner.arch }} in
94+
X64)
95+
desired_vexctl_filename='vexctl-windows-amd64.exe'
96+
vexctl_executable_name=vexctl.exe
97+
;;
98+
*)
99+
log_error "unsupported architecture $arch"
100+
exit 1
101+
;;
102+
esac
103+
;;
104+
*)
105+
log_error "unsupported architecture $arch"
106+
exit 1
107+
;;
108+
esac
109+
110+
SUDO=
111+
if "${{ inputs.use-sudo }}" == "true" && command -v sudo >/dev/null; then
112+
SUDO=sudo
113+
fi
114+
115+
semver='^([0-9]+\.){0,2}(\*|[0-9]+)$'
116+
if [[ ${{ inputs.vexctl-release }} =~ $semver ]]; then
117+
log_info "Custom vexctl version '${{ inputs.vexctl-release }}' requested"
118+
else
119+
log_error "Unable to validate requested vexctl version: '${{ inputs.vexctl-release }}'"
120+
exit 1
121+
fi
122+
123+
# Download custom vexctl
124+
log_info "Downloading platform-specific version '${{ inputs.vexctl-release }}' of vexctl...\n https://github.com/openvex/vexctl/releases/download/v${{ inputs.vexctl-release }}/${desired_vexctl_filename}"
125+
$SUDO curl -sL https://github.com/openvex/vexctl/releases/download/v${{ inputs.vexctl-release }}/${desired_vexctl_filename} -o ${vexctl_executable_name}
126+
127+
VEXCTL_CERT=https://github.com/openvex/vexctl/releases/download/v${{ inputs.vexctl-release }}/${desired_vexctl_filename}.pem
128+
VEXCTL_SIG=https://github.com/openvex/vexctl/releases/download/v${{ inputs.vexctl-release }}/${desired_vexctl_filename}.sig
129+
130+
log_info "Using cosign to verify signature of desired vexctl version"
131+
cosign verify-blob --certificate $VEXCTL_CERT --signature $VEXCTL_SIG \
132+
--certificate-identity "https://github.com/openvex/vexctl/.github/workflows/release.yaml@refs/tags/v${{ inputs.vexctl-release }}" \
133+
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" ${vexctl_executable_name}
134+
retVal=$?
135+
if [[ $retVal -eq 0 ]]; then
136+
$SUDO chmod +x ${vexctl_executable_name}
137+
log_info "Installation complete!"
138+
else
139+
log_error "Unable to validate vexctl version: '${{ inputs.vexctl-release }}'"
140+
exit 1
141+
fi
142+
143+
- if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
144+
run: echo "${{ inputs.install-dir }}" >> $GITHUB_PATH
145+
shell: bash
146+
- if: ${{ runner.os == 'Windows' }}
147+
run: echo "${{ inputs.install-dir }}" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
148+
shell: pwsh

0 commit comments

Comments
 (0)