-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
75 lines (68 loc) · 2.27 KB
/
action.yaml
File metadata and controls
75 lines (68 loc) · 2.27 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
name: 'Cloudentity CAC'
description: 'Manage Cloudentity configuration as code'
inputs:
args:
description: 'Arguments to pass to cac'
required: true
outputs:
result:
description: 'Result of the cac command'
value: ${{ steps.run.outputs.result }}
runs:
using: 'composite'
steps:
- name: Restore cached binary
id: cache
uses: actions/cache@v4
with:
path: /tmp/cac
key: cac-${{ runner.os }}-${{ runner.arch }}-${{ github.action_ref || github.ref_name }}
- name: Download pre-built binary
id: download
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
continue-on-error: true
run: |
VERSION="${{ github.action_ref || github.ref_name }}"
REPO="${{ github.action_repository }}"
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
esac
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
URL="https://github.com/${REPO}/releases/download/${VERSION}/cac_${OS}_${ARCH}.tar.gz"
curl -sfL "$URL" -o /tmp/cac.tar.gz
tar -xzf /tmp/cac.tar.gz -C /tmp cac
chmod +x /tmp/cac
echo "Downloaded pre-built binary from ${URL}"
- name: Check for preinstalled Go
id: go-check
if: steps.download.outcome == 'failure'
shell: bash
run: |
if command -v go > /dev/null; then
echo "Using preinstalled Go: $(go version)"
echo "preinstalled=true" >> "$GITHUB_OUTPUT"
else
echo "preinstalled=false" >> "$GITHUB_OUTPUT"
fi
- name: Install Go
if: steps.download.outcome == 'failure' && steps.go-check.outputs.preinstalled != 'true'
uses: actions/setup-go@v5
with:
go-version-file: '${{ github.action_path }}/go.mod'
- name: Build from source
if: steps.download.outcome == 'failure'
shell: bash
run: |
cd "${{ github.action_path }}"
CGO_ENABLED=0 go build -o /tmp/cac .
echo "Built from source (no pre-built binary available for this ref)"
- name: Run cac
id: run
shell: bash
run: |
/tmp/cac ${{ inputs.args }} > /tmp/out
content=$(awk '{printf "%s\\n", $0}' /tmp/out)
echo "result=$content" >> "$GITHUB_OUTPUT"