Skip to content

Commit a13ff19

Browse files
authored
Merge pull request #41 from jamesstocktonj1/feat/setup-action
feat: add `setup-componentize-go` action
2 parents 4b751a4 + 2681619 commit a13ff19

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: 'setup-componentize-go'
2+
description: 'Setup componentize-go for your Github Actions workflow'
3+
4+
inputs:
5+
version:
6+
required: false
7+
description: 'version of componentize-go to setup'
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Cache componentize-go
13+
id: cache
14+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # 5.0.4
15+
with:
16+
path: ${{ runner.tool_cache }}/componentize-go/${{ inputs.version }}
17+
key: componentize-go-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }}
18+
19+
- name: Download componentize-go (Unix)
20+
if: steps.cache.outputs.cache-hit != 'true' && runner.os != 'Windows'
21+
shell: bash
22+
run: |
23+
case "${{ runner.os }}-${{ runner.arch }}" in
24+
Linux-X64) os="linux"; arch="amd64" ;;
25+
Linux-ARM64) os="linux"; arch="arm64" ;;
26+
macOS-X64) os="darwin"; arch="amd64" ;;
27+
macOS-ARM64) os="darwin"; arch="arm64" ;;
28+
*) echo "Unsupported platform: ${{ runner.os }}-${{ runner.arch }}"; exit 1 ;;
29+
esac
30+
31+
archive="componentize-go-${os}-${arch}.tar.gz"
32+
curl -fsSL "https://github.com/bytecodealliance/componentize-go/releases/download/${{ inputs.version }}/${archive}" \
33+
-o "${archive}"
34+
tar -xzf "${archive}"
35+
36+
cache_dir="${{ runner.tool_cache }}/componentize-go/${{ inputs.version }}"
37+
mkdir -p "${cache_dir}"
38+
cp componentize-go "${cache_dir}/"
39+
chmod +x "${cache_dir}/componentize-go"
40+
41+
- name: Download componentize-go (Windows)
42+
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Windows'
43+
shell: pwsh
44+
run: |
45+
$archive = "componentize-go-windows-amd64.zip"
46+
Invoke-WebRequest `
47+
-Uri "https://github.com/bytecodealliance/componentize-go/releases/download/${{ inputs.version }}/$archive" `
48+
-OutFile $archive
49+
Expand-Archive -Path $archive -DestinationPath .
50+
51+
$cache_dir = "${{ runner.tool_cache }}/componentize-go/${{ inputs.version }}"
52+
New-Item -ItemType Directory -Force -Path $cache_dir | Out-Null
53+
Copy-Item componentize-go.exe "$cache_dir/"
54+
55+
- name: Add componentize-go to PATH
56+
shell: bash
57+
run: echo "${{ runner.tool_cache }}/componentize-go/${{ inputs.version }}" >> "$GITHUB_PATH"

0 commit comments

Comments
 (0)