Skip to content

Commit 47dc521

Browse files
authored
Generalise (#291)
2 parents 23cd90a + 3e62ace commit 47dc521

File tree

14 files changed

+103
-66
lines changed

14 files changed

+103
-66
lines changed

.github/workflows/distribute.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
GH_TOKEN: ${{ github.token }}
4242
TAG: ${{ inputs.tag }}
4343
run: |
44-
gh release download "$TAG" --pattern 'vmatch-*64.tar.gz'
44+
gh release download "$TAG" --pattern '${{ github.event.repository.name }}-*64.tar.gz'
4545
ls -- *.tar.gz
4646
- name: Render formula template
4747
uses: anttiharju/actions/render-template@v1
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
committer: "anttiharju[bot]"
5656
message: |
57-
Update vmatch formula to ${{ inputs.tag }}
57+
Update ${{ github.event.repository.name }} formula to ${{ inputs.tag }}
5858
59-
https://github.com/anttiharju/vmatch/blob/${{ github.sha }}/.github/workflows/distribute.yml
59+
https://github.com/${{ github.repository }}/blob/${{ github.sha }}/.github/workflows/distribute.yml
6060
working-directory: homebrew-tap

.github/workflows/plan.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
name: action-validator
4343
uses: anttiharju/actions/action-validator@v1
4444

45-
- if: always() && (steps.changed.outputs.github_actions_workflows == 'true' || github.event_name == 'push')
45+
- if: always() && (steps.changed.outputs.github_actions_workflows == 'true' || github.event_name != 'pull_request')
4646
name: actionlint
4747
uses: anttiharju/actions/actionlint@v1
4848

@@ -54,33 +54,35 @@ jobs:
5454
name: EditorConfig-Checker
5555
uses: anttiharju/actions/editorconfig-checker@v1
5656

57-
- if: always() && (steps.changed.outputs.binary == 'true' || github.event_name == 'push')
57+
- if: always() && (steps.changed.outputs.binary == 'true' || github.event_name != 'pull_request')
5858
name: go build
5959
uses: anttiharju/actions/go-build@v1
6060

61-
- if: always() && (steps.changed.outputs.binary == 'true' || github.event_name == 'push')
61+
- if: always() && (steps.changed.outputs.binary == 'true' || github.event_name != 'pull_request')
6262
name: go test
6363
shell: sh
6464
run: |
6565
go test ./...
6666
67-
- if: always() && (steps.changed.outputs.go_code == 'true' || github.event_name == 'push')
67+
- if: always() && (steps.changed.outputs.go_code == 'true' || github.event_name != 'pull_request')
6868
name: golangci-lint
6969
uses: anttiharju/actions/golangci-lint@v1
7070

71-
- if: always() && (steps.changed.outputs.documentation == 'true' || github.event_name == 'push')
71+
- if: always() && (steps.changed.outputs.documentation == 'true' || github.event_name != 'pull_request')
7272
name: MkDocs
7373
uses: anttiharju/actions/mkdocs-build-strict@v1
7474

7575
- if: always()
76-
name: no-yaml
77-
uses: anttiharju/actions/no-yaml@v1
76+
name: keep-yml
77+
uses: anttiharju/actions/keep-yml@v1
7878

79-
- if: always() && (steps.changed.outputs.md_and_yml == 'true' || github.event_name == 'push')
79+
- if: always() && (steps.changed.outputs.md_and_yml == 'true' || github.event_name != 'pull_request')
8080
name: Prettier
8181
uses: anttiharju/actions/prettier@v1
82+
with:
83+
patterns: "{*.yml,*.md}"
8284

83-
- if: always() && (steps.changed.outputs.scripts == 'true' || github.event_name == 'push')
85+
- if: always() && (steps.changed.outputs.scripts == 'true' || github.event_name != 'pull_request')
8486
name: ShellCheck
8587
uses: anttiharju/actions/shellcheck@v1
8688
outputs:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ jobs:
7171
GH_TOKEN: ${{ github.token }}
7272
TAG: ${{ steps.release.outputs.tag }}
7373
run: |
74-
find . -maxdepth 1 -name 'vmatch-*-*.tar.gz' -exec gh release upload "$TAG" {} \;
74+
find . -maxdepth 1 -name '${{ github.event.repository.name }}-*-*.tar.gz' -exec gh release upload "$TAG" {} \;
7575
outputs:
7676
tag: ${{ steps.release.outputs.tag }}

.gitignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ go.work.sum
2424
# Env file
2525
.env
2626

27-
# Binary
28-
vmatch
27+
# Ignore files at repo root without extension, except LICENSE
28+
/[!.]*
29+
!/LICENSE
30+
!/*/
31+
!/*.*
2932

3033
# Docs build output
3134
site
@@ -38,8 +41,8 @@ homebrew-tap
3841

3942
# Brew dist local render
4043
dist/brew/values.cache
41-
dist/brew/vmatch.rb
42-
dist/brew/vmatch.template.rb
44+
dist/brew/*.rb
45+
!dist/brew/template.rb
4346

4447
# Binary archives
4548
*.tar.gz

dist/brew/render.bash

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,47 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
44

55
template_file=template.rb
66
if [[ ! -f "$template_file" ]]; then
7-
echo "Formula template is missing: $template_file"
8-
exit 1
7+
echo "Formula template is missing: $template_file"
8+
exit 1
99
fi
1010

11+
repo_root="$(git rev-parse --show-toplevel)"
12+
repo_name="$(basename "$repo_root")"
13+
1114
# Mock GitHub Actions env
12-
GITHUB_REPOSITORY=anttiharju/vmatch
15+
GITHUB_REPOSITORY="anttiharju/$repo_name"
16+
TAG="$(git tag --sort=-creatordate | head -n1)"
1317

14-
# Mock what would normally be provided by release job so we can run this locally
15-
TAG="$(basename "$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq .tarball_url)")"
18+
# Check if we need to download binaries by comparing cached tag with latest release tag
19+
tag_cache_file="$repo_root/tag"
20+
cached_tag=""
21+
[[ -f "$tag_cache_file" ]] && cached_tag="$(cat "$tag_cache_file")"
1622

17-
# Cache logic for faster iteration
23+
# Cache logic for faster template iteration
1824
cache_file=values.cache
1925
quick_mode=false
2026
[[ " $* " =~ " --quick " ]] && quick_mode=true
2127

2228
set -a
2329
if [[ "$quick_mode" == true ]] && [[ -f "$cache_file" ]]; then
24-
echo "Using cached values from $cache_file"
25-
cat "$cache_file"
30+
echo "Using cached values from $cache_file"
31+
cat "$cache_file"
2632
else
27-
echo "Generating fresh values"
28-
gh release download "$TAG" --pattern 'vmatch-*64.tar.gz'
29-
mv vmatch-*64.tar.gz ../../
30-
source values.bash | tee "$cache_file"
33+
echo "Generating fresh values"
34+
35+
# Only download binaries if the tag has changed or cache doesn't exist
36+
if [[ "$cached_tag" != "$TAG" ]]; then
37+
echo "New release detected: $TAG (was: ${cached_tag:-none})"
38+
gh release download "$TAG" --pattern "$repo_name-*64.tar.gz"
39+
find . -name "$repo_name-*64.tar.gz" -exec mv {} "$repo_root/" \;
40+
41+
# Cache the latest tag
42+
echo "$TAG" > "$tag_cache_file"
43+
else
44+
echo "Using cached binaries for tag: $TAG"
45+
fi
46+
47+
source values.bash | tee "$cache_file"
3148
fi
3249

3350
# Cache file is gitignored and we cannot guarantee its existence
@@ -36,15 +53,15 @@ source "$cache_file"
3653
set +a
3754

3855
# Template
39-
envsubst < "$template_file" > vmatch.rb
56+
envsubst < "$template_file" > ".$repo_name.rb"
4057

4158
local_tap=false
4259
[[ " $* " =~ " --local-tap " ]] && local_tap=true
4360
if [[ "$local_tap" == true ]]; then
44-
dir=../../Formula
45-
mkdir -p "$dir"
46-
cp vmatch.rb "$dir"
61+
dir="$repo_root/Formula"
62+
mkdir -p "$dir"
63+
cp ".$repo_name.rb" "$dir"
4764
fi
4865

4966
# Easier visual diffing
50-
cp "$template_file" vmatch.template.rb
67+
cp "$template_file" ".$repo_name.template.rb"

dist/brew/template.rb

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,51 @@
11
# frozen_string_literal: true
22

3+
# This file is generated by render.bash, do not edit manually.
34
class ${class_name} < Formula
45
desc '${description}'
56
homepage '${homepage}'
67
version '${version}'
7-
license 'GPL-3.0-only'
8+
license 'MIT'
89

910
on_macos do
1011
if Hardware::CPU.intel?
11-
url 'https://github.com/anttiharju/vmatch/releases/download/v${version}/vmatch-darwin-amd64.tar.gz'
12+
url 'https://github.com/${repo_owner}/${repo_name}/releases/download/v${version}/${repo_name}-darwin-amd64.tar.gz'
1213
sha256 '${darwin_amd64_sha256}'
1314

1415
def install
15-
bin.install "vmatch"
16+
bin.install '${repo_name}'
1617
end
1718
end
1819
if Hardware::CPU.arm?
19-
url "https://github.com/anttiharju/vmatch/releases/download/v${version}/vmatch-darwin-arm64.tar.gz"
20+
url 'https://github.com/${repo_owner}/${repo_name}/releases/download/v${version}/${repo_name}-darwin-arm64.tar.gz'
2021
sha256 '${darwin_arm64_sha256}'
2122

2223
def install
23-
bin.install "vmatch"
24+
bin.install '${repo_name}'
2425
end
2526
end
2627
end
2728

2829
on_linux do
29-
if Hardware::CPU.intel?
30-
if Hardware::CPU.is_64_bit?
31-
url "https://github.com/anttiharju/vmatch/releases/download/v${version}/vmatch-linux-amd64.tar.gz"
32-
sha256 '${linux_amd64_sha256}'
30+
if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
31+
url 'https://github.com/${repo_owner}/${repo_name}/releases/download/v${version}/${repo_name}-linux-amd64.tar.gz'
32+
sha256 '${linux_amd64_sha256}'
3333

34-
def install
35-
bin.install "vmatch"
36-
end
34+
def install
35+
bin.install '${repo_name}'
3736
end
3837
end
39-
if Hardware::CPU.arm?
40-
if Hardware::CPU.is_64_bit?
41-
url "https://github.com/anttiharju/vmatch/releases/download/v${version}/vmatch-linux-arm64.tar.gz"
42-
sha256 '${linux_arm64_sha256}'
38+
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
39+
url 'https://github.com/${repo_owner}/${repo_name}/releases/download/v${version}/${repo_name}-linux-arm64.tar.gz'
40+
sha256 '${linux_arm64_sha256}'
4341

44-
def install
45-
bin.install "vmatch"
46-
end
42+
def install
43+
bin.install '${repo_name}'
4744
end
4845
end
4946
end
5047

5148
test do
52-
system "#{bin}/vmatch doctor"
49+
system "#{bin}/${repo_name} version"
5350
end
5451
end

dist/brew/values.bash

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ capture() {
1212
}
1313

1414
REPO_ROOT="$(git rev-parse --show-toplevel)"
15+
1516
repo_name="$(basename "$GITHUB_REPOSITORY")"
17+
echo "repo_name=\"$repo_name\""
1618

1719
capture class_name "$(awk 'BEGIN{print toupper(substr("'"$repo_name"'",1,1)) substr("'"$repo_name"'",2)}')"
1820
capture description "$(gh repo view --json description --jq .description)"
1921
capture homepage "$(gh api "repos/$GITHUB_REPOSITORY" --jq .homepage)"
2022
capture version "${TAG#v}"
21-
capture darwin_amd64_sha256 "$(shasum -a 256 "$REPO_ROOT/vmatch-darwin-amd64.tar.gz" | cut -d ' ' -f1)"
22-
capture darwin_arm64_sha256 "$(shasum -a 256 "$REPO_ROOT/vmatch-darwin-arm64.tar.gz" | cut -d ' ' -f1)"
23-
capture linux_amd64_sha256 "$(shasum -a 256 "$REPO_ROOT/vmatch-linux-amd64.tar.gz" | cut -d ' ' -f1)"
24-
capture linux_arm64_sha256 "$(shasum -a 256 "$REPO_ROOT/vmatch-linux-arm64.tar.gz" | cut -d ' ' -f1)"
23+
capture repo_owner "${GITHUB_REPOSITORY%%/*}"
24+
capture darwin_amd64_sha256 "$(shasum -a 256 "$REPO_ROOT/$repo_name-darwin-amd64.tar.gz" | cut -d ' ' -f1)"
25+
capture darwin_arm64_sha256 "$(shasum -a 256 "$REPO_ROOT/$repo_name-darwin-arm64.tar.gz" | cut -d ' ' -f1)"
26+
capture linux_amd64_sha256 "$(shasum -a 256 "$REPO_ROOT/$repo_name-linux-amd64.tar.gz" | cut -d ' ' -f1)"
27+
capture linux_arm64_sha256 "$(shasum -a 256 "$REPO_ROOT/$repo_name-linux-arm64.tar.gz" | cut -d ' ' -f1)"

dist/github/release.bash

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ echo "$os"
1212
echo "$arch"
1313

1414
rm -rf "tmp/$os-$arch"
15+
repo_name="$(basename "$(pwd)")"
1516
# Disable CGO to ensure static linking
16-
CGO_ENABLED=0 go build -ldflags "-s -w -buildid=github-$version" -trimpath -o "tmp/$os-$arch/vmatch"
17+
CGO_ENABLED=0 go build -ldflags "-s -w -buildid=github-$version" -trimpath -o "tmp/$os-$arch/$repo_name"
1718

1819
cp LICENSE "tmp/$os-$arch"
1920
cp -r docs/* "tmp/$os-$arch"
@@ -24,4 +25,4 @@ while IFS= read -r -d '' file; do
2425
docs+=("$file")
2526
done < <(git ls-files -z --others '*.md')
2627

27-
tar -czf "$repo_root/vmatch-$os-$arch.tar.gz" LICENSE "${docs[@]}" vmatch
28+
tar -czf "$repo_root/$repo_name-$os-$arch.tar.gz" LICENSE "${docs[@]}" "$repo_name"

internal/choose/choose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func Wrapper(ctx context.Context, args []string) int {
3838
}
3939

4040
if firstArgIs("version", args) {
41-
return version.Print()
41+
return version.Print("vmatch")
4242
}
4343

4444
if firstArgIs("doctor", args) {

internal/language/language.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
"github.com/anttiharju/vmatch/internal/exitcode"
1414
"github.com/anttiharju/vmatch/internal/scripts"
15+
"github.com/anttiharju/vmatch/internal/wrapper"
1516
"github.com/anttiharju/vmatch/pkg/install"
16-
"github.com/anttiharju/vmatch/pkg/wrapper"
1717
)
1818

1919
type WrappedLanguage struct {

0 commit comments

Comments
 (0)