diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9a7e75f..99bdbc3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,16 +40,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} - - name: Upload artifacts + name: Update version env: GIT_COMMITTER_NAME: Actions Automation GIT_COMMITTER_EMAIL: GIT_AUTHOR_NAME: Actions Automation GIT_AUTHOR_EMAIL: run: | - git add dist - git restore --staged dist/config.yaml dist/\*.zip dist/\*.tar.gz dist/\*.txt dist/\*.txt.sig - git commit -m "Add artifacts for ${GITHUB_REF#refs/tags/}" + tag="${GITHUB_REF#refs/tags/}" + sed -i -e "s/^tag=.*/tag=\"${tag}\"/" gh-repo-explore + git add gh-repo-explore + git commit -m "Update version to ${tag}" if [[ $GITHUB_REF != *-* ]]; then git push origin HEAD:trunk fi diff --git a/.goreleaser.yml b/.goreleaser.yml index f45cbe4..1b8d1fe 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -15,10 +15,8 @@ builds: - 386 - amd64 archives: - - wrap_in_directory: true - format_overrides: - - goos: windows - format: zip + - format: binary + name_template: "{{ .Binary }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}" checksum: disable: false signs: diff --git a/gh-repo-explore b/gh-repo-explore index 2416bd3..9691226 100755 --- a/gh-repo-explore +++ b/gh-repo-explore @@ -1,40 +1,63 @@ -#!/bin/bash +#!/usr/bin/env bash set -e -extensionPath="$(dirname "$0")" -arch="$(uname -m)" +tag="v0.0.3" +repo="samcoe/gh-repo-explore" +extension_path="$(dirname "$0")" +tag_path="${extension_path}/dist/${tag}" +exe="gh-repo-explore" -if uname -a | grep Msys > /dev/null; then - if [ $arch = "x86_64" ]; then - exec "${extensionPath}/dist/gh-repo-explore_windows_amd64/gh-repo-explore" "$@" - elif [ $arch = "i686" ]; then - exec "${extensionPath}/dist/gh-repo-explore_windows_386/gh-repo-explore" "$@" - elif [ $arch = "i386" ]; then - exec "${extensionPath}/dist/gh-repo-explore_windows_386/gh-repo-explore" "$@" +determine_platform() { + local arch="$(uname -m)" + if uname -a | grep Msys > /dev/null; then + if [ $arch == "x86_64" ]; then + platform="windows_amd64" + elif [ $arch == "i686" ]; then + platform="windows_386" + elif [ $arch == "i386" ]; then + platform="windows_386" + fi + elif uname -a | grep Darwin > /dev/null; then + if [ $arch == "x86_64" ]; then + platform="darwin_amd64" + fi + elif uname -a | grep Linux > /dev/null; then + if [ $arch == "x86_64" ]; then + platform="linux_amd64" + elif [ $arch == "i686" ]; then + platform="linux_386" + elif [ $arch == "i386" ]; then + platform="linux_386" + fi fi -elif uname -a | grep Darwin > /dev/null; then - if [ $arch = "x86_64" ]; then - exec "${extensionPath}/dist/gh-repo-explore_darwin_amd64/gh-repo-explore" "$@" - fi -elif uname -a | grep Linux > /dev/null; then - if [ $arch = "x86_64" ]; then - exec "${extensionPath}/dist/gh-repo-explore_linux_amd64/gh-repo-explore" "$@" - elif [ $arch = "i686" ]; then - exec "${extensionPath}/dist/gh-repo-explore_linux_386/gh-repo-explore" "$@" - elif [ $arch = "i386" ]; then - exec "${extensionPath}/dist/gh-repo-explore_linux_386/gh-repo-explore" "$@" - fi -fi +} -if [ "$(which go)" = "" ]; then - echo "go must be installed to use this gh extension on this platform" - exit 1 -fi +download_latest_release() { + mkdir -p "${tag_path}" + gh release -R"${repo}" download "${tag}" --pattern "*${platform}*" --dir="${tag_path}" + if [ $platform == "windows_amd64" ] || [ $platform == "windows_386" ]; then + mv "${tag_path}/${exe}_${tag}_${platform}.exe" "${tag_path}/${exe}" + else + mv "${tag_path}/${exe}_${tag}_${platform}" "${tag_path}/${exe}" + chmod +x "${tag_path}/${exe}" + fi +} -exe="cmd.out" +determine_platform -cd "${extensionPath}" > /dev/null -go build -o "${exe}" -cd - > /dev/null +if [ "${platform}" == "" ]; then + if [ "$(which go)" == "" ]; then + echo "go must be installed to use this gh extension on this platform" + exit 1 + fi + mkdir -p "${tag_path}" + cd "${extensionPath}" > /dev/null + go build -o "${tag_path}/${exe}" + cd - > /dev/null +else + if [ ! -d tag_path ]; then + download_latest_release + fi +fi -exec "${extensionPath}/${exe}" "$@" +exec "${tag_path}/${exe}" "$@"