forked from kubernetes-sigs/release-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
157 lines (140 loc) · 5.3 KB
/
action.yml
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: setup-bom
author: cpanato
description: 'Installs bom and includes it in your path'
branding:
icon: 'package'
color: 'blue'
# This is pinned to the last major release, we have to bump it for each action version.
inputs:
bom-release:
description: 'bom release version to be installed'
required: false
default: '0.6.0'
install-dir:
description: 'Where to install the bom binary'
required: false
default: '$HOME/.bom'
use-sudo:
description: 'set to true if install-dir location requires sudo privs'
required: false
default: 'false'
runs:
using: "composite"
steps:
- uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 # v3.4.0
with:
install-dir: ${{ inputs.install-dir }}
use-sudo: ${{ inputs.use-sudo }}
- shell: bash
run: |
#!/usr/bin/env bash
# bom install script
shopt -s expand_aliases
if [ -z "$NO_COLOR" ]; then
alias log_info="echo -e \"\033[1;32mINFO\033[0m:\""
alias log_error="echo -e \"\033[1;31mERROR\033[0m:\""
else
alias log_info="echo \"INFO:\""
alias log_error="echo \"ERROR:\""
fi
set -e
mkdir -p ${{ inputs.install-dir }}
trap "popd >/dev/null" EXIT
pushd ${{ inputs.install-dir }} > /dev/null
bom_executable_name='bom'
case ${{ runner.os }} in
Linux)
case ${{ runner.arch }} in
X64)
desired_bom_filename='bom-amd64-linux'
;;
ARM)
desired_bom_filename='bom-arm-linux'
;;
ARM64)
desired_bom_filename='bom-arm64-linux'
;;
*)
log_error "unsupported architecture $arch"
exit 1
;;
esac
;;
macOS)
case ${{ runner.arch }} in
X64)
desired_bom_filename='bom-amd64-darwin'
;;
ARM64)
desired_bom_filename='bom-arm64-darwin'
;;
*)
log_error "unsupported architecture $arch"
exit 1
;;
esac
;;
Windows)
case ${{ runner.arch }} in
X64)
desired_bom_filename='bom-amd64-windows.exe'
bom_executable_name=bom.exe
;;
*)
log_error "unsupported architecture $arch"
exit 1
;;
esac
;;
*)
log_error "unsupported architecture $arch"
exit 1
;;
esac
SUDO=
if "${{ inputs.use-sudo }}" == "true" && command -v sudo >/dev/null; then
SUDO=sudo
fi
semver='^([0-9]+\.){0,2}(\*|[0-9]+)$'
if [[ ${{ inputs.bom-release }} =~ $semver ]]; then
log_info "Custom bom version '${{ inputs.bom-release }}' requested"
else
log_error "Unable to validate requested bom version: '${{ inputs.bom-release }}'"
exit 1
fi
# Download custom bom
log_info "Downloading platform-specific version '${{ inputs.bom-release }}' of bom...\n https://github.com/kubernetes-sigs/bom/releases/download/v${{ inputs.bom-release }}/${desired_bom_filename}"
$SUDO curl -sL https://github.com/kubernetes-sigs/bom/releases/download/v${{ inputs.bom-release }}/${desired_bom_filename} -o ${bom_executable_name}
BOM_CERT=https://github.com/kubernetes-sigs/bom/releases/download/v${{ inputs.bom-release }}/${desired_bom_filename}.pem
BOM_SIG=https://github.com/kubernetes-sigs/bom/releases/download/v${{ inputs.bom-release }}/${desired_bom_filename}.sig
log_info "Using cosign to verify signature of desired bom version"
cosign verify-blob --certificate $BOM_CERT --signature $BOM_SIG \
--certificate-identity "https://github.com/kubernetes-sigs/bom/.github/workflows/release.yml@refs/tags/v${{ inputs.bom-release }}" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" ${bom_executable_name}
retVal=$?
if [[ $retVal -eq 0 ]]; then
$SUDO chmod +x ${bom_executable_name}
log_info "Installation complete!"
else
log_error "Unable to validate bom version: '${{ inputs.bom-release }}'"
exit 1
fi
- if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
run: echo "${{ inputs.install-dir }}" >> $GITHUB_PATH
shell: bash
- if: ${{ runner.os == 'Windows' }}
run: echo "${{ inputs.install-dir }}" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
shell: pwsh