Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
125 lines (119 loc) · 4.53 KB
/
Copy pathaction.yml
File metadata and controls
125 lines (119 loc) · 4.53 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Setup spec-to-rest
description: Download the spec-to-rest native binary; expose its absolute path via the `binary-path` output for subsequent steps to invoke.
author: HardMax71
branding:
icon: check-circle
color: green
inputs:
version:
description: Release tag to install (e.g. v2.0.0). Use "latest" for the most recent published release.
required: false
default: latest
repository:
description: Source repository to fetch the release from. Override only when forking.
required: false
default: HardMax71/spec_to_rest
github-token:
description: |
Token used for the GitHub API call that resolves "latest". Leave empty to fall back
to the workflow's `github.token`. Action metadata defaults are not expression-
evaluated, so we cannot write `${{ github.token }}` here — the fallback happens
inside the step.
required: false
default: ""
outputs:
version:
description: The concrete release tag that was installed.
value: ${{ steps.resolve.outputs.version }}
binary-path:
description: Absolute path to the installed binary.
value: ${{ runner.temp }}/spec-to-rest/spec-to-rest${{ runner.os == 'Windows' && '.exe' || '' }}
runs:
using: composite
steps:
- id: detect
name: Detect runner platform
shell: bash
env:
OS: ${{ runner.os }}
ARCH: ${{ runner.arch }}
run: |
set -euo pipefail
case "$OS/$ARCH" in
Linux/X64) plat=linux-amd64; ext=tar.gz; binary=spec-to-rest ;;
macOS/ARM64) plat=macos-arm64; ext=tar.gz; binary=spec-to-rest ;;
macOS/X64) plat=macos-amd64; ext=tar.gz; binary=spec-to-rest ;;
Windows/X64) plat=windows-amd64; ext=zip; binary=spec-to-rest.exe ;;
*)
echo "::error::unsupported runner platform: $OS/$ARCH (need Linux/X64, macOS/ARM64, macOS/X64, or Windows/X64)"
exit 1
;;
esac
{
echo "platform=$plat"
echo "ext=$ext"
echo "binary=$binary"
echo "archive=spec-to-rest-${plat}.${ext}"
} >> "$GITHUB_OUTPUT"
- id: resolve
name: Resolve release tag
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token != '' && inputs.github-token || github.token }}
REPO: ${{ inputs.repository }}
REQUESTED: ${{ inputs.version }}
run: |
set -euo pipefail
if ! command -v gh >/dev/null 2>&1; then
echo "::error::the GitHub CLI ('gh') is required but not installed on this runner"
exit 1
fi
if [ -z "${GH_TOKEN:-}" ]; then
echo "::error::no GitHub token available. Pass 'github-token' or grant the workflow access to github.token."
exit 1
fi
if [ "$REQUESTED" = "latest" ]; then
tag=$(gh api "repos/$REPO/releases/latest" --jq .tag_name)
else
tag="$REQUESTED"
# Fail fast if the tag does not exist.
gh api "repos/$REPO/releases/tags/$tag" --jq .tag_name >/dev/null
fi
echo "version=$tag" >> "$GITHUB_OUTPUT"
- name: Download and install
shell: bash
env:
REPO: ${{ inputs.repository }}
TAG: ${{ steps.resolve.outputs.version }}
ARCHIVE: ${{ steps.detect.outputs.archive }}
BINARY: ${{ steps.detect.outputs.binary }}
EXT: ${{ steps.detect.outputs.ext }}
run: |
set -euo pipefail
install_dir="${RUNNER_TEMP}/spec-to-rest"
mkdir -p "$install_dir"
url="https://github.com/${REPO}/releases/download/${TAG}/${ARCHIVE}"
echo "Fetching $url"
archive_path="${RUNNER_TEMP}/${ARCHIVE}"
curl -fL --retry 3 -o "$archive_path" "$url"
case "$EXT" in
tar.gz) tar -xzf "$archive_path" -C "$install_dir" ;;
zip) unzip -q "$archive_path" -d "$install_dir" ;;
esac
binary_path="${install_dir}/${BINARY}"
if [ ! -f "$binary_path" ]; then
echo "::error::binary not found after extraction: $binary_path"
ls -la "$install_dir"
exit 1
fi
if [ "$EXT" = "tar.gz" ]; then chmod +x "$binary_path"; fi
- name: Verify
shell: bash
env:
BINARY_PATH: ${{ runner.temp }}/spec-to-rest/spec-to-rest${{ runner.os == 'Windows' && '.exe' || '' }}
VERSION: ${{ steps.resolve.outputs.version }}
PLATFORM: ${{ steps.detect.outputs.platform }}
run: |
set -euo pipefail
"$BINARY_PATH" --help >/dev/null
echo "Installed spec-to-rest $VERSION on $PLATFORM at $BINARY_PATH"