Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
105 lines (94 loc) · 3.34 KB
/
Copy pathaction.yml
File metadata and controls
105 lines (94 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Setup shp
description: Download shp from a shapelang GitHub release and add it to PATH.
inputs:
version:
description: Release tag to install. Defaults to the action ref when it is a version tag, otherwise latest.
required: false
repository:
description: Repository to download release assets from.
required: false
default: timbrinded/shapelang
token:
description: GitHub token used by gh to download release assets.
required: false
runs:
using: composite
steps:
- name: Download shp
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
ACTION_REF: ${{ github.action_ref }}
REPOSITORY: ${{ inputs.repository }}
GH_TOKEN: ${{ inputs.token || github.token }}
run: |
set -euo pipefail
version="$INPUT_VERSION"
if [ -z "$version" ]; then
case "$ACTION_REF" in
v*) version="$ACTION_REF" ;;
*) version="latest" ;;
esac
fi
case "$RUNNER_OS" in
Linux)
os="linux"
executable="shp"
;;
macOS)
os="darwin"
executable="shp"
;;
Windows)
os="windows"
executable="shp.exe"
;;
*)
echo "Unsupported runner OS: $RUNNER_OS" >&2
exit 1
;;
esac
case "$RUNNER_ARCH" in
X64) arch="x64" ;;
ARM64) arch="arm64" ;;
*)
echo "Unsupported runner architecture: $RUNNER_ARCH" >&2
exit 1
;;
esac
if [ "$os" = "windows" ] && [ "$arch" = "arm64" ]; then
echo "No shp release asset is published for Windows ARM64." >&2
exit 1
fi
if [ "$os" = "darwin" ] && [ "$arch" = "x64" ]; then
echo "No shp release asset is published for macOS x64." >&2
exit 1
fi
asset="shp-$os-$arch.tar.gz"
download_dir="$(mktemp -d)"
install_dir="$(mktemp -d)"
if [ "$version" = "latest" ]; then
gh release download --repo "$REPOSITORY" --pattern "$asset" --pattern checksums.txt --dir "$download_dir"
else
gh release download "$version" --repo "$REPOSITORY" --pattern "$asset" --pattern checksums.txt --dir "$download_dir"
fi
if command -v sha256sum >/dev/null 2>&1; then
(cd "$download_dir" && sha256sum --check checksums.txt --ignore-missing)
elif command -v shasum >/dev/null 2>&1; then
expected="$(awk -v asset="$asset" '$2 == "./" asset { print $1 }' "$download_dir/checksums.txt")"
actual="$(shasum -a 256 "$download_dir/$asset" | awk '{ print $1 }')"
if [ -z "$expected" ] || [ "$expected" != "$actual" ]; then
echo "Checksum verification failed for $asset." >&2
exit 1
fi
else
echo "No SHA-256 tool found; skipping checksum verification." >&2
fi
tar -xzf "$download_dir/$asset" -C "$install_dir"
chmod +x "$install_dir/$executable" 2>/dev/null || true
path_to_add="$install_dir"
if [ "$RUNNER_OS" = "Windows" ] && command -v cygpath >/dev/null 2>&1; then
path_to_add="$(cygpath -w "$install_dir")"
fi
echo "$path_to_add" >> "$GITHUB_PATH"
"$install_dir/$executable" --help >/dev/null