diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3351ff8..28db2f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,5 +53,13 @@ jobs: run: | go run cmd/gh-setup/main.go --repo k1LoW/gh-setup gh-setup -v + shell: bash + + - name: Run setup as a action (1/2) + uses: ./ + with: + repo: k1LoW/tbls + - name: Run setup as a action (2/2) + run: tbls version shell: bash diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1d8cb89 --- /dev/null +++ b/action.yml @@ -0,0 +1,36 @@ +name: 'Setup asset of Github Releases' +description: 'GitHub Action for gh-setup' +inputs: + github-token: + description: The GitHub token + default: ${{ github.token }} + required: false + repo: + description: "Target repository [OWNER/REPO]" + required: true + bin-dir: + description: "Executable path" + default: "" + required: false + force: + description: "Enable force setup" + default: false + required: false +runs: + using: "composite" + steps: + - + id: install-gh-setup + run: scripts/install-gh-setup.sh + shell: bash + env: + GH_SETUP_GITHUB_TOKEN: ${{ inputs.github-token }} + - + run: scripts/run-gh-setup.sh + shell: bash + env: + GH_SETUP_GITHUB_TOKEN: ${{ inputs.github-token }} + GH_SETUP_REPO: ${{ inputs.repo }} + GH_SETUP_BIN_DIR: ${{ inputs.bin-dir }} + GH_SETUP_FORCE: ${{ inputs.force }} + GH_SETUP_BIN: ${{ steps.install-gh-setup.outputs.bin }} diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh old mode 100644 new mode 100755 diff --git a/scripts/install-gh-setup.sh b/scripts/install-gh-setup.sh new file mode 100755 index 0000000..33e79f7 --- /dev/null +++ b/scripts/install-gh-setup.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -e + +token=${GH_SETUP_GITHUB_TOKEN} +if [ -z "${token}" ]; then + token=${GITHUB_TOKEN} +fi +repo="k1LoW/gh-setup" +tag="$(curl -sL -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${token}" https://api.github.com/repos/${repo}/releases/latest | grep tag_name | awk -F':' '{print $2}' | awk -F'\"' '{print $2}')" +arch="$(uname -m)" + +if uname -a | grep Msys > /dev/null; then + if [ $arch = "x86_64" ]; then + exe="gh-setup_${tag}_windows_amd64.exe" + fi + bin="${TEMP}/gh-setup" +elif uname -a | grep Darwin > /dev/null; then + if [ $arch = "x86_64" ]; then + exe="gh-setup_${tag}_darwin_amd64" + elif [ $arch = "arm64" ]; then + exe="gh-setup_${tag}_darwin_arm64" + fi + bin="${TMPDIR}gh-setup" +elif uname -a | grep Linux > /dev/null; then + if [ $arch = "x86_64" ]; then + exe="gh-setup_${tag}_linux_amd64" + fi + bin="/tmp/gh-setup" +fi + +# download +curl -sL -o ${bin} https://github.com/k1LoW/gh-setup/releases/download/${tag}/${exe} +chmod +x ${bin} +${bin} -v +echo "bin=${bin}" >> ${GITHUB_OUTPUT} diff --git a/scripts/run-gh-setup.sh b/scripts/run-gh-setup.sh new file mode 100755 index 0000000..23369a8 --- /dev/null +++ b/scripts/run-gh-setup.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +bin="${GH_SETUP_BIN}" +token=${GH_SETUP_GITHUB_TOKEN} +if [ -z "${token}" ]; then + token=${GITHUB_TOKEN} +fi +repo=${GH_SETUP_REPO} +bindir=${GH_SETUP_BIN_DIR} +force=${GH_SETUP_FORCE} + +${bin} --repo ${repo} --bin-dir=${GH_SETUP_BIN_DIR}