Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action.yml for Action #6

Merged
merged 2 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 36 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Empty file modified scripts/entrypoint.sh
100644 → 100755
Empty file.
35 changes: 35 additions & 0 deletions scripts/install-gh-setup.sh
Original file line number Diff line number Diff line change
@@ -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}
13 changes: 13 additions & 0 deletions scripts/run-gh-setup.sh
Original file line number Diff line number Diff line change
@@ -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}