Skip to content

Commit 9711e27

Browse files
committed
Add GitHub action for installation
0 parents  commit 9711e27

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

.github/workflows/test-install.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: test install
2+
3+
on:
4+
push:
5+
branches:
6+
- install
7+
pull_request:
8+
branches:
9+
- install
10+
11+
jobs:
12+
run:
13+
name: Install ${{ matrix.job.target }}
14+
runs-on: ${{ matrix.job.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
job:
19+
- target: x86_64-unknown-linux-gnu
20+
os: ubuntu-24.04
21+
- target: x86_64-pc-windows-msvc
22+
os: windows-2022
23+
- target: aarch64-apple-darwin
24+
os: macos-14
25+
- target: x86_64-apple-darwin
26+
os: macos-13
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Install
33+
# Command needs to be wrapped in single quotes so backslashes are preserved for Windows paths
34+
run: "'${{ github.workspace }}${{ runner.os == 'Windows' && '\\' || '/' }}main.sh'"
35+
shell: bash
36+
env:
37+
DEVA_INSTALL_VERSION: latest
38+
39+
- name: Verify
40+
run: deva --version

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Install deva Action
2+
3+
-----
4+
5+
This is an action to install deva in your GitHub Actions workflow.
6+
7+
## Usage
8+
9+
You must [use](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses) this action in one of your [jobs](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobs)' [steps](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idsteps):
10+
11+
```yaml
12+
- name: Install deva
13+
uses: DataDog/datadog-agent-dev@install
14+
```
15+
16+
For strict security guarantees, it's best practice to [pin](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-versioned-actions) the action to a specific commit (of the [`install` branch](https://github.com/DataDog/datadog-agent-dev/tree/install)) like so:
17+
18+
```yaml
19+
- name: Install deva
20+
uses: DataDog/datadog-agent-dev@install
21+
```
22+
23+
## Options
24+
25+
Name | Default | Description
26+
--- | --- | ---
27+
`version` | `latest` | The version of deva to install (e.g. `0.4.2`).
28+
29+
## External consumers
30+
31+
It's possible to use the [install script](https://github.com/DataDog/datadog-agent-dev/blob/install/main.sh) outside of GitHub Actions assuming you set up your environment as follows:
32+
33+
- Set every [option](#options) to an environment variable prefixed by `DEVA_INSTALL_`, uppercased and with hyphens replaced by underscores.
34+
- Set the `DEVA_INSTALL_PATH` environment variable to the directory where you want to install deva.
35+
- Set the `DEVA_INSTALL_PLATFORM` environment variable to the current platform using one of the following values:
36+
- `linux`
37+
- `windows`
38+
- `macos`
39+
- Set the `DEVA_INSTALL_ARCH` environment variable to the current architecture using one of the following values:
40+
- `X64`
41+
- `ARM64`
42+
- Install [pipx](https://github.com/pypa/pipx) as a fallback installation method for when there is no [standalone binary](https://deva.pypa.io/latest/install/#standalone-binaries) available. In this case, nothing will be written to `GITHUB_PATH`.

action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Install deva Action
2+
description: Install and configure deva
3+
branding:
4+
icon: download-cloud
5+
color: purple
6+
7+
inputs:
8+
version:
9+
description: The version of deva to install
10+
default: latest
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Install and configure deva
16+
# Command needs to be wrapped in single quotes so backslashes are preserved for Windows paths
17+
run: "'${{ github.action_path }}${{ runner.os == 'Windows' && '\\' || '/' }}main.sh'"
18+
shell: bash
19+
env:
20+
DEVA_INSTALL_VERSION: ${{ inputs.version }}

main.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
PURPLE="\033[1;35m"
6+
RESET="\033[0m"
7+
TARGET_PLATFORM=${DEVA_INSTALL_PLATFORM:-${RUNNER_OS}}
8+
TARGET_PLATFORM=${TARGET_PLATFORM,,}
9+
TARGET_ARCH=${DEVA_INSTALL_ARCH:-${RUNNER_ARCH}}
10+
TARGET_ARCH=${TARGET_ARCH,,}
11+
12+
if [[ "${TARGET_PLATFORM}" == "windows" ]]; then
13+
SEP="\\"
14+
else
15+
SEP="/"
16+
fi
17+
INSTALL_PATH="${DEVA_INSTALL_PATH:-${RUNNER_TOOL_CACHE}${SEP}.deva}"
18+
19+
install_deva() {
20+
mkdir -p "${INSTALL_PATH}"
21+
archive="${INSTALL_PATH}${SEP}$1"
22+
23+
echo -e "${PURPLE}Downloading deva ${DEVA_INSTALL_VERSION}${RESET}\n"
24+
if [[ "${DEVA_INSTALL_VERSION}" == "latest" ]]; then
25+
curl -sSLo "${archive}" "https://github.com/DataDog/datadog-agent-dev/releases/latest/download/$1"
26+
else
27+
curl -sSLo "${archive}" "https://github.com/DataDog/datadog-agent-dev/releases/download/deva-v${DEVA_INSTALL_VERSION}/$1"
28+
fi
29+
30+
if [[ "${archive}" =~ \.zip$ ]]; then
31+
if [[ "${TARGET_PLATFORM}" == "windows" ]]; then
32+
7z -bso0 -bsp0 x "${archive}" -o"${INSTALL_PATH}"
33+
else
34+
unzip "${archive}" -d "${INSTALL_PATH}"
35+
fi
36+
else
37+
tar -xzf "${archive}" -C "${INSTALL_PATH}"
38+
fi
39+
rm "${archive}"
40+
41+
echo -e "${PURPLE}Installing deva ${DEVA_INSTALL_VERSION}${RESET}"
42+
"${INSTALL_PATH}${SEP}deva" --version
43+
"${INSTALL_PATH}${SEP}deva" self cache dist --remove
44+
45+
if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then
46+
echo "${INSTALL_PATH}" >> "${GITHUB_PATH}"
47+
fi
48+
}
49+
50+
fallback_install_deva() {
51+
echo -e "${PURPLE}Installing deva ${DEVA_INSTALL_VERSION}${RESET}"
52+
if [[ "${DEVA_INSTALL_VERSION}" == "latest" ]]; then
53+
pipx install --pip-args=--upgrade deva
54+
else
55+
pipx install "deva==${DEVA_INSTALL_VERSION}"
56+
fi
57+
58+
deva --version
59+
}
60+
61+
if [[ "${TARGET_PLATFORM}" == "linux" ]]; then
62+
if [[ "${TARGET_ARCH}" == "x64" ]]; then
63+
install_deva "deva-x86_64-unknown-linux-gnu.tar.gz"
64+
elif [[ "${TARGET_ARCH}" == "ARM64" ]]; then
65+
install_deva "deva-aarch64-unknown-linux-gnu.tar.gz"
66+
else
67+
fallback_install_deva
68+
fi
69+
elif [[ "${TARGET_PLATFORM}" == "windows" ]]; then
70+
if [[ "${TARGET_ARCH}" == "x64" ]]; then
71+
install_deva "deva-x86_64-pc-windows-msvc.zip"
72+
else
73+
fallback_install_deva
74+
fi
75+
elif [[ "${TARGET_PLATFORM}" == "macos" ]]; then
76+
if [[ "${TARGET_ARCH}" == "ARM64" ]]; then
77+
install_deva "deva-aarch64-apple-darwin.tar.gz"
78+
elif [[ "${TARGET_ARCH}" == "x64" ]]; then
79+
install_deva "deva-x86_64-apple-darwin.tar.gz"
80+
else
81+
fallback_install_deva
82+
fi
83+
else
84+
fallback_install_deva
85+
fi

0 commit comments

Comments
 (0)