From a3af5ec561d2b8ba189def6df8588551aa02ca4d Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 12 Feb 2023 22:35:48 +0900 Subject: [PATCH 1/2] Add action.yml --- action.yml | 36 ++++++++++++++++++++++++++++++++++++ scripts/install-gh-setup.sh | 31 +++++++++++++++++++++++++++++++ scripts/run-gh-setup.sh | 10 ++++++++++ 3 files changed, 77 insertions(+) create mode 100644 action.yml create mode 100644 scripts/install-gh-setup.sh create mode 100644 scripts/run-gh-setup.sh diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..56d07ba --- /dev/null +++ b/action.yml @@ -0,0 +1,36 @@ +name: 'Setup asset of Github Releases' +description: 'GitHub Action for gh-setup' +outputs: + 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/install-gh-setup.sh b/scripts/install-gh-setup.sh new file mode 100644 index 0000000..264b4f2 --- /dev/null +++ b/scripts/install-gh-setup.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -e + +token=${GH_SETUP_GITHUB_TOKEN} +repo="k1LoW/gh-setup" +tag="$(curl -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} +echo "bin=${bin}" >> ${GITHUB_OUTPUT} diff --git a/scripts/run-gh-setup.sh b/scripts/run-gh-setup.sh new file mode 100644 index 0000000..6f0a5ee --- /dev/null +++ b/scripts/run-gh-setup.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -e + +bin=${GH_SETUP_BIN} +token=${GH_SETUP_GITHUB_TOKEN} +repo=${GH_SETUP_REPO} +bindir=${GH_SETUP_BIN_DIR} +force=${GH_SETUP_FORCE} + +${bin} --repo ${repo} --bin-dir=${GH_SETUP_BIN_DIR} From 7597c5982fbc40c3a972b56fd0ff67690e0d96df Mon Sep 17 00:00:00 2001 From: k1LoW Date: Sun, 12 Feb 2023 22:41:08 +0900 Subject: [PATCH 2/2] Add action test --- .github/workflows/ci.yml | 8 ++++++++ action.yml | 2 +- scripts/entrypoint.sh | 0 scripts/install-gh-setup.sh | 12 ++++++++---- scripts/run-gh-setup.sh | 5 ++++- 5 files changed, 21 insertions(+), 6 deletions(-) mode change 100644 => 100755 scripts/entrypoint.sh mode change 100644 => 100755 scripts/install-gh-setup.sh mode change 100644 => 100755 scripts/run-gh-setup.sh 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 index 56d07ba..1d8cb89 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,6 @@ name: 'Setup asset of Github Releases' description: 'GitHub Action for gh-setup' -outputs: +inputs: github-token: description: The GitHub token default: ${{ github.token }} 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 old mode 100644 new mode 100755 index 264b4f2..33e79f7 --- a/scripts/install-gh-setup.sh +++ b/scripts/install-gh-setup.sh @@ -2,30 +2,34 @@ set -e token=${GH_SETUP_GITHUB_TOKEN} +if [ -z "${token}" ]; then + token=${GITHUB_TOKEN} +fi repo="k1LoW/gh-setup" -tag="$(curl -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}')" +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 + 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 + 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 + 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 old mode 100644 new mode 100755 index 6f0a5ee..23369a8 --- a/scripts/run-gh-setup.sh +++ b/scripts/run-gh-setup.sh @@ -1,8 +1,11 @@ #!/usr/bin/env bash set -e -bin=${GH_SETUP_BIN} +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}