Skip to content

Commit

Permalink
Use GITHUB_TOKEN variable
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er committed Oct 2, 2023
1 parent bc64e1d commit db0ef6a
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 41 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
13 changes: 9 additions & 4 deletions .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 All @@ -18,11 +20,11 @@ jobs:
matrix:
include:
- container: alpine:latest
preinstall: apk add bash coreutils curl git
preinstall: apk add bash coreutils curl git jq
- container: centos:latest
preinstall: dnf -y --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos && dnf -y install git
preinstall: dnf -y --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos && dnf -y install git jq
- container: ubuntu:latest
preinstall: apt-get -y update && apt-get -y install curl git
preinstall: apt-get -y update && apt-get -y install curl git jq

runs-on: ubuntu-latest

Expand All @@ -42,6 +44,9 @@ jobs:
runs-on: macos-latest

steps:
- name: Preinstall
run: brew install jq

- name: Test plugin
uses: asdf-vm/actions/plugin-test@v1
with:
Expand Down
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
7 changes: 6 additions & 1 deletion .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
*out
*logs
external
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
2 changes: 1 addition & 1 deletion .trunk/actions
2 changes: 1 addition & 1 deletion .trunk/notifications
35 changes: 26 additions & 9 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
version: 0.1
cli:
version: 1.0.1
version: 1.16.2
lint:
disabled:
- checkov
- trivy
- trufflehog
enabled:
- actionlint@1.6.26
- git-diff-check
- actionlint@1.6.21
- gitleaks@8.15.0
- markdownlint@0.32.2
- prettier@2.7.1
- shellcheck@0.8.0
- shfmt@3.5.0
- gitleaks@8.18.0
- markdownlint@0.37.0
- prettier@3.0.3
- shellcheck@0.9.0
- shfmt@3.6.0
- yamllint@1.32.0
runtimes:
enabled:
- go@1.18.3
- node@16.14.2
- go@1.21.0
- node@18.12.1
- python@3.10.8
plugins:
sources:
- id: trunk
ref: v1.2.5
uri: https://github.com/trunk-io/plugins
actions:
enabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
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
54 changes: 38 additions & 16 deletions bin/install
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
#!/usr/bin/env bash

set -euo pipefail
shopt -s inherit_errexit 2>/dev/null || true

[[ -z ${ASDF_INSTALL_TYPE+x} ]] && echo "ASDF_INSTALL_TYPE is required" && exit 1
[[ -z ${ASDF_INSTALL_VERSION+x} ]] && echo "ASDF_INSTALL_VERSION is required" && exit 1
[[ -z ${ASDF_INSTALL_PATH+x} ]] && echo "ASDF_INSTALL_PATH is required" && exit 1

install() {
function gh_curl() {
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 -fLsS "$@"
fi
}

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

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

local bin_install_path="${install_path}/bin"

local platform
platform=$(uname | tr '[:upper:]' '[:lower:]')
case "${platform}" in
darwin) platform="macos" ;;
esac
platform=$(uname -s | tr '[:upper:]' '[:lower:]')

local arch
arch=$(uname -m)
case "${arch}" in
x86_64) arch="amd64" ;;
aarch64) arch="arm64" ;;
aarch64) arch=arm64 ;;
x86_64) arch=amd64 ;;
esac

local download_url
download_url="https://github.com/databus23/helm-diff/releases/download/v${version}/helm-diff-${platform}-${arch}.tgz"

local repo="databus23/helm-diff"

local download_filename
case "${version}" in
3.[01].* | [012].*) download_url="https://github.com/databus23/helm-diff/releases/download/v${version}/helm-diff-${platform}.tgz" ;;
3.[01].* | [012].*) download_filename="helm-diff-${platform}.tgz" ;;
*) download_filename="helm-diff-${platform}-${arch}.tgz" ;;
esac

mkdir -p "${bin_install_path}"
if [[ -n ${GITHUB_TOKEN-} ]] || [[ -n ${GITHUB_API_TOKEN-} ]]; then
local asset_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 "Asset ${download_filename} not found in a release ${prefix}${version}."
exit 1
fi
else
download_url="https://github.com/${repo}/releases/download/${prefix}${version}/${download_filename}"
fi

echo "Downloading helm-diff from ${download_url}"
echo "Downloading ${download_filename} from release ${prefix}${version} from ${download_url}"

pushd "${bin_install_path}" >/dev/null
mkdir -p "${bin_install_path}"

curl -sL "${download_url}" | tar zx -O diff/bin/diff >"${bin_install_path}/helm-diff"
gh_curl -H "Accept: application/octet-stream" "${download_url}" | tar zx -O diff/bin/diff >"${bin_install_path}/helm-diff"

chmod +x "${bin_install_path}/helm-diff"

Expand All @@ -54,8 +78,6 @@ command: "helm-diff"
END
ln -s . "${install_path}/helm-diff"

popd >/dev/null

if command -v helm >/dev/null && ! helm plugin list | sed 1d | grep -qs '^diff[[:space:]]'; then
helm plugin install "${install_path}/helm-diff" || true
fi
Expand Down
26 changes: 19 additions & 7 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
#!/usr/bin/env bash

releases_path=https://api.github.com/repos/databus23/helm-diff/releases
cmd="curl -s"
if [[ -n ${GITHUB_API_TOKEN} ]]; then
cmd="${cmd} -H 'Authorization: token ${GITHUB_API_TOKEN}'"
fi
set -euo pipefail
shopt -s inherit_errexit 2>/dev/null || true

cmd="${cmd} ${releases_path}"
function gh_curl() {
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 "$@"
fi
}

function filter_versions() {
grep -E '^[0-9]'
}

function sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

echo $(eval "${cmd}" | grep -oE 'tag_name": ".{1,15}",' | sed 's/tag_name\": \"v//;s/\",//' | sort_versions)
repo="databus23/helm-diff"
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 db0ef6a

Please sign in to comment.