Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
113 lines (103 loc) · 4.02 KB
/
Copy pathaction.yml
File metadata and controls
113 lines (103 loc) · 4.02 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
name: "cws — Chrome Web Store CLI"
description: "Upload and publish Chrome extensions to the Chrome Web Store"
branding:
icon: upload-cloud
color: blue
inputs:
args:
description: "Whitespace-separated cws arguments (e.g. 'upload ./dist --publish')"
required: true
version:
description: "Exact cws release version to install (e.g. v1.3.1)"
required: true
client-id:
description: "OAuth2 client ID (sets CWS_CLIENT_ID)"
required: false
client-secret:
description: "OAuth2 client secret (sets CWS_CLIENT_SECRET)"
required: false
refresh-token:
description: "OAuth2 refresh token (sets CWS_REFRESH_TOKEN)"
required: false
publisher-id:
description: "Chrome Web Store publisher ID (sets CWS_PUBLISHER_ID)"
required: false
extension-id:
description: "Extension ID (sets CWS_EXTENSION_ID)"
required: false
runs:
using: "composite"
steps:
- name: Install cws
shell: bash
env:
CWS_ACTION_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
if [[ ! "$CWS_ACTION_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
echo "version must be an exact release tag such as v1.3.1" >&2
exit 1
fi
case "$(uname -s)" in
Linux) os=linux ;;
Darwin) os=darwin ;;
*) echo "unsupported operating system: $(uname -s)" >&2; exit 1 ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*) echo "unsupported architecture: $(uname -m)" >&2; exit 1 ;;
esac
archive="cws_${os}_${arch}.tar.gz"
base_url="https://github.com/vaughnbosu/cws-cli/releases/download/${CWS_ACTION_VERSION}"
temp_dir="$(mktemp -d "${RUNNER_TEMP}/cws-action.XXXXXX")"
install_dir="${RUNNER_TEMP}/cws-action/bin"
curl --fail --silent --show-error --location \
--output "$temp_dir/$archive" "$base_url/$archive"
curl --fail --silent --show-error --location \
--output "$temp_dir/checksums.txt" "$base_url/checksums.txt"
expected="$(awk -v file="$archive" '$2 == file { print $1; exit }' "$temp_dir/checksums.txt")"
if [[ -z "$expected" ]]; then
echo "checksum not found for $archive" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
actual="$(sha256sum "$temp_dir/$archive" | awk '{ print $1 }')"
else
actual="$(shasum -a 256 "$temp_dir/$archive" | awk '{ print $1 }')"
fi
if [[ "$actual" != "$expected" ]]; then
echo "checksum verification failed for $archive" >&2
exit 1
fi
mkdir -p "$install_dir"
tar -xzf "$temp_dir/$archive" -C "$temp_dir" cws
install -m 755 "$temp_dir/cws" "$install_dir/cws"
echo "$install_dir" >> "$GITHUB_PATH"
"$install_dir/cws" version
- name: Run cws
shell: bash
env:
CWS_ACTION_ARGS: ${{ inputs.args }}
INPUT_CLIENT_ID: ${{ inputs.client-id }}
INPUT_CLIENT_SECRET: ${{ inputs.client-secret }}
INPUT_REFRESH_TOKEN: ${{ inputs.refresh-token }}
INPUT_PUBLISHER_ID: ${{ inputs.publisher-id }}
INPUT_EXTENSION_ID: ${{ inputs.extension-id }}
run: |
set -euo pipefail
if [[ "$CWS_ACTION_ARGS" == *$'\n'* ]]; then
echo "args must be a single line" >&2
exit 1
fi
[[ -n "$INPUT_CLIENT_ID" ]] && export CWS_CLIENT_ID="$INPUT_CLIENT_ID"
[[ -n "$INPUT_CLIENT_SECRET" ]] && export CWS_CLIENT_SECRET="$INPUT_CLIENT_SECRET"
[[ -n "$INPUT_REFRESH_TOKEN" ]] && export CWS_REFRESH_TOKEN="$INPUT_REFRESH_TOKEN"
[[ -n "$INPUT_PUBLISHER_ID" ]] && export CWS_PUBLISHER_ID="$INPUT_PUBLISHER_ID"
[[ -n "$INPUT_EXTENSION_ID" ]] && export CWS_EXTENSION_ID="$INPUT_EXTENSION_ID"
read -r -a cws_args <<< "$CWS_ACTION_ARGS"
if (( ${#cws_args[@]} == 0 )); then
echo "args cannot be empty" >&2
exit 1
fi
cws "${cws_args[@]}"