diff --git a/.github/actions/setup-componentize-go/action.yml b/.github/actions/setup-componentize-go/action.yml new file mode 100644 index 0000000..d30f1e0 --- /dev/null +++ b/.github/actions/setup-componentize-go/action.yml @@ -0,0 +1,57 @@ +name: 'setup-componentize-go' +description: 'Setup componentize-go for your Github Actions workflow' + +inputs: + version: + required: false + description: 'version of componentize-go to setup' + +runs: + using: 'composite' + steps: + - name: Cache componentize-go + id: cache + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # 5.0.4 + with: + path: ${{ runner.tool_cache }}/componentize-go/${{ inputs.version }} + key: componentize-go-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }} + + - name: Download componentize-go (Unix) + if: steps.cache.outputs.cache-hit != 'true' && runner.os != 'Windows' + shell: bash + run: | + case "${{ runner.os }}-${{ runner.arch }}" in + Linux-X64) os="linux"; arch="amd64" ;; + Linux-ARM64) os="linux"; arch="arm64" ;; + macOS-X64) os="darwin"; arch="amd64" ;; + macOS-ARM64) os="darwin"; arch="arm64" ;; + *) echo "Unsupported platform: ${{ runner.os }}-${{ runner.arch }}"; exit 1 ;; + esac + + archive="componentize-go-${os}-${arch}.tar.gz" + curl -fsSL "https://github.com/bytecodealliance/componentize-go/releases/download/${{ inputs.version }}/${archive}" \ + -o "${archive}" + tar -xzf "${archive}" + + cache_dir="${{ runner.tool_cache }}/componentize-go/${{ inputs.version }}" + mkdir -p "${cache_dir}" + cp componentize-go "${cache_dir}/" + chmod +x "${cache_dir}/componentize-go" + + - name: Download componentize-go (Windows) + if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Windows' + shell: pwsh + run: | + $archive = "componentize-go-windows-amd64.zip" + Invoke-WebRequest ` + -Uri "https://github.com/bytecodealliance/componentize-go/releases/download/${{ inputs.version }}/$archive" ` + -OutFile $archive + Expand-Archive -Path $archive -DestinationPath . + + $cache_dir = "${{ runner.tool_cache }}/componentize-go/${{ inputs.version }}" + New-Item -ItemType Directory -Force -Path $cache_dir | Out-Null + Copy-Item componentize-go.exe "$cache_dir/" + + - name: Add componentize-go to PATH + shell: bash + run: echo "${{ runner.tool_cache }}/componentize-go/${{ inputs.version }}" >> "$GITHUB_PATH"