Skip to content

Commit

Permalink
GITHUB_TOKEN variable (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er authored Oct 2, 2023
1 parent b9722c4 commit 915b907
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 23 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2

[bin/**]
indent_style = tab
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: CI

permissions: {}

on:
workflow_dispatch:
workflow_dispatch: {}
pull_request:
paths-ignore:
- "**.md"
Expand Down Expand Up @@ -37,6 +39,8 @@ jobs:
uses: asdf-vm/actions/plugin-test@v1
with:
command: hcl2json </dev/null
env:
GITHUB_TOKEN: ${{ github.token }}

macos:
runs-on: macos-latest
Expand All @@ -49,3 +53,5 @@ jobs:
uses: asdf-vm/actions/plugin-test@v1
with:
command: hcl2json </dev/null
env:
GITHUB_TOKEN: ${{ github.token }}
6 changes: 4 additions & 2 deletions .github/workflows/trunk.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Trunk

permissions: {}

on:
workflow_dispatch:
workflow_dispatch: {}
pull_request:
paths-ignore:
- LICENSE
Expand All @@ -15,7 +17,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Trunk Check
uses: trunk-io/trunk-action@v1
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
?.*
.vscode
1 change: 1 addition & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
24 changes: 15 additions & 9 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
version: 0.1
cli:
version: 1.3.1
version: 1.16.2
lint:
disabled:
- checkov
- trivy
- trufflehog
enabled:
- [email protected]
- git-diff-check
- [email protected].22
- gitleaks@8.15.2
- markdownlint@0.33.0
- prettier@2.8.3
- [email protected].26
- gitleaks@8.18.0
- markdownlint@0.37.0
- prettier@3.0.3
- [email protected]
- shfmt@3.5.0
- shfmt@3.6.0
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
actions:
enabled:
- trunk-announce
Expand All @@ -23,5 +29,5 @@ actions:
plugins:
sources:
- id: trunk
ref: v0.0.8
ref: v1.2.5
uri: https://github.com/trunk-io/plugins
10 changes: 10 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
25 changes: 16 additions & 9 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ shopt -s inherit_errexit 2>/dev/null || true
[[ -z ${ASDF_INSTALL_PATH+x} ]] && echo "ASDF_INSTALL_PATH is required" && exit 1

function gh_curl() {
if [[ -n ${GITHUB_API_TOKEN:-} ]]; then
curl -fsS -H "Authorization: token ${GITHUB_API_TOKEN}" "$@"
if [[ -n ${GITHUB_TOKEN-} ]]; then
curl -fLsS -H "Authorization: token ${GITHUB_TOKEN}" "$@"
elif [[ -n ${GITHUB_API_TOKEN-} ]]; then
curl -fLsS -H "Authorization: token ${GITHUB_API_TOKEN}" "$@"
else
curl -fsS "$@"
curl -fLsS "$@"
fi
}

function install() {
# set -x
local install_type=$1
[[ ${install_type} != "version" ]] && echo "install type, ${install_type}, is not supported" && exit 1

local prefix="v"
local version=$2
local install_path=$3

Expand All @@ -37,19 +41,22 @@ function install() {

local download_url

if [[ -n ${GITHUB_API_TOKEN:-} ]]; then
local repo="tmccombs/hcl2json"
local download_filename="hcl2json_${platform}_${arch}"

if [[ -n ${GITHUB_TOKEN-} ]] || [[ -n ${GITHUB_API_TOKEN-} ]]; then
local asset_url
asset_url="https://api.github.com/repos/tmccombs/hcl2json/releases/tags/v${version}"
download_url=$(gh_curl -H "Accept: application/vnd.github.v3.raw" "${asset_url}" | jq -r ".assets | map(select(.name == \"hcl2json_${platform}_${arch}\"))[0].url")
asset_url="https://api.github.com/repos/${repo}/releases/tags/${prefix}${version}"
download_url=$(gh_curl -H "Accept: application/vnd.github.v3.raw" "${asset_url}" | jq -r ".assets | map(select(.name == \"${download_filename}\"))[0].url")
if [[ ${download_url} == null ]]; then
echo "Package hcl2json_${platform}_${arch} not found in a release."
echo "Asset ${download_filename} not found in a release ${prefix}${version}."
exit 1
fi
else
download_url="https://github.com/tmccombs/hcl2json/releases/download/v${version}/hcl2json_${platform}_${arch}"
download_url="https://github.com/${repo}/releases/download/${prefix}${version}/${download_filename}"
fi

echo "Downloading hcl2json from ${download_url}"
echo "Downloading ${download_filename} from release ${prefix}${version} from ${download_url}"

mkdir -p "${bin_install_path}"

Expand Down
7 changes: 5 additions & 2 deletions bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ set -euo pipefail
shopt -s inherit_errexit 2>/dev/null || true

function gh_curl() {
if [[ -n ${GITHUB_API_TOKEN:-} ]]; then
if [[ -n ${GITHUB_TOKEN-} ]]; then
curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$@"
elif [[ -n ${GITHUB_API_TOKEN-} ]]; then
curl -s -H "Authorization: token ${GITHUB_API_TOKEN}" "$@"
else
curl -s "$@"
Expand All @@ -20,6 +22,7 @@ function sort_versions() {
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

releases_path=https://api.github.com/repos/tmccombs/hcl2json/releases
repo="tmccombs/hcl2json"
releases_path=https://api.github.com/repos/${repo}/releases

gh_curl "${releases_path}" | grep -oE 'tag_name": "v.{1,15}",' | sed 's/tag_name\": \"v//;s/\",//' | filter_versions | sort_versions | xargs echo

0 comments on commit 915b907

Please sign in to comment.