Skip to content

Commit 4292e73

Browse files
authored
Merge pull request #154 from RafaelJohn9/develop
Develop
2 parents 608f2ad + 20b5d53 commit 4292e73

File tree

4 files changed

+119
-168
lines changed

4 files changed

+119
-168
lines changed

.github/workflows/build.yml

Lines changed: 79 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18+
1819
- name: Setup Rust
1920
uses: actions-rs/toolchain@v1
2021
with:
2122
toolchain: stable
23+
2224
- name: Publish to crates.io
2325
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
2426

@@ -30,95 +32,17 @@ jobs:
3032
fail-fast: false
3133
matrix:
3234
build:
33-
- {
34-
NAME: linux-x64-glibc,
35-
OS: ubuntu-22.04,
36-
TOOLCHAIN: stable,
37-
TARGET: x86_64-unknown-linux-gnu,
38-
NPM_PUBLISH: true,
39-
PYPI_PUBLISH: true
40-
}
41-
- {
42-
NAME: linux-x64-musl,
43-
OS: ubuntu-22.04,
44-
TOOLCHAIN: stable,
45-
TARGET: x86_64-unknown-linux-musl,
46-
NPM_PUBLISH: false,
47-
PYPI_PUBLISH: true
48-
}
49-
- {
50-
NAME: linux-x86-glibc,
51-
OS: ubuntu-22.04,
52-
TOOLCHAIN: stable,
53-
TARGET: i686-unknown-linux-gnu,
54-
NPM_PUBLISH: false,
55-
PYPI_PUBLISH: false
56-
}
57-
- {
58-
NAME: linux-x86-musl,
59-
OS: ubuntu-22.04,
60-
TOOLCHAIN: stable,
61-
TARGET: i686-unknown-linux-musl,
62-
NPM_PUBLISH: false,
63-
PYPI_PUBLISH: true
64-
}
65-
- {
66-
NAME: linux-arm64-glibc,
67-
OS: ubuntu-22.04,
68-
TOOLCHAIN: stable,
69-
TARGET: aarch64-unknown-linux-gnu,
70-
NPM_PUBLISH: true,
71-
PYPI_PUBLISH: true
72-
}
73-
- {
74-
NAME: linux-arm64-musl,
75-
OS: ubuntu-22.04,
76-
TOOLCHAIN: stable,
77-
TARGET: aarch64-unknown-linux-musl,
78-
NPM_PUBLISH: false,
79-
PYPI_PUBLISH: true
80-
}
81-
82-
- {
83-
NAME: win32-x64-msvc,
84-
OS: windows-latest,
85-
TOOLCHAIN: stable,
86-
TARGET: x86_64-pc-windows-msvc,
87-
NPM_PUBLISH: true,
88-
PYPI_PUBLISH: true
89-
}
90-
- {
91-
NAME: win32-x86-msvc,
92-
OS: windows-latest,
93-
TOOLCHAIN: stable,
94-
TARGET: i686-pc-windows-msvc,
95-
NPM_PUBLISH: false,
96-
PYPI_PUBLISH: true
97-
}
98-
- {
99-
NAME: win32-arm64-msvc,
100-
OS: windows-latest,
101-
TOOLCHAIN: stable,
102-
TARGET: aarch64-pc-windows-msvc,
103-
NPM_PUBLISH: true,
104-
PYPI_PUBLISH: false
105-
}
106-
- {
107-
NAME: darwin-x64,
108-
OS: macos-15,
109-
TOOLCHAIN: stable,
110-
TARGET: x86_64-apple-darwin,
111-
NPM_PUBLISH: true,
112-
PYPI_PUBLISH: true
113-
}
114-
- {
115-
NAME: darwin-arm64,
116-
OS: macos-15,
117-
TOOLCHAIN: stable,
118-
TARGET: aarch64-apple-darwin,
119-
NPM_PUBLISH: true,
120-
PYPI_PUBLISH: true
121-
}
35+
- { NAME: linux-x64-glibc, OS: ubuntu-22.04, TOOLCHAIN: stable, TARGET: x86_64-unknown-linux-gnu, NPM_PUBLISH: true, PYPI_PUBLISH: true }
36+
- { NAME: linux-x64-musl, OS: ubuntu-22.04, TOOLCHAIN: stable, TARGET: x86_64-unknown-linux-musl, NPM_PUBLISH: false, PYPI_PUBLISH: true }
37+
- { NAME: linux-x86-glibc, OS: ubuntu-22.04, TOOLCHAIN: stable, TARGET: i686-unknown-linux-gnu, NPM_PUBLISH: false, PYPI_PUBLISH: false }
38+
- { NAME: linux-x86-musl, OS: ubuntu-22.04, TOOLCHAIN: stable, TARGET: i686-unknown-linux-musl, NPM_PUBLISH: false, PYPI_PUBLISH: true }
39+
- { NAME: linux-arm64-glibc, OS: ubuntu-22.04, TOOLCHAIN: stable, TARGET: aarch64-unknown-linux-gnu, NPM_PUBLISH: true, PYPI_PUBLISH: true }
40+
- { NAME: linux-arm64-musl, OS: ubuntu-22.04, TOOLCHAIN: stable, TARGET: aarch64-unknown-linux-musl, NPM_PUBLISH: false, PYPI_PUBLISH: true }
41+
- { NAME: win32-x64-msvc, OS: windows-latest, TOOLCHAIN: stable, TARGET: x86_64-pc-windows-msvc, NPM_PUBLISH: true, PYPI_PUBLISH: true }
42+
- { NAME: win32-x86-msvc, OS: windows-latest, TOOLCHAIN: stable, TARGET: i686-pc-windows-msvc, NPM_PUBLISH: false, PYPI_PUBLISH: true }
43+
- { NAME: win32-arm64-msvc, OS: windows-latest, TOOLCHAIN: stable, TARGET: aarch64-pc-windows-msvc, NPM_PUBLISH: true, PYPI_PUBLISH: false }
44+
- { NAME: darwin-x64, OS: macos-15, TOOLCHAIN: stable, TARGET: x86_64-apple-darwin, NPM_PUBLISH: true, PYPI_PUBLISH: true }
45+
- { NAME: darwin-arm64, OS: macos-15, TOOLCHAIN: stable, TARGET: aarch64-apple-darwin, NPM_PUBLISH: true, PYPI_PUBLISH: true }
12246

12347
steps:
12448
- uses: actions/checkout@v4
@@ -141,71 +65,72 @@ jobs:
14165
if: runner.os != 'Windows'
14266
shell: bash
14367
run: |
68+
VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//')
69+
14470
# Build
14571
if [[ "${{ runner.os }}" == "Linux" ]]; then
14672
cross build --release --target ${{ matrix.build.TARGET }}
14773
else
14874
cargo build --release --target ${{ matrix.build.TARGET }}
14975
fi
150-
151-
# Copy binary
152-
echo "BINARY_NAME=gh-templates" >> $GITHUB_ENV
153-
cp target/${{ matrix.build.TARGET }}/release/gh-templates .
154-
chmod +x gh-templates
15576
156-
- name: Setup MinGW environment (Windows MinGW builds)
157-
if: runner.os == 'Windows' && contains(matrix.build.TARGET, 'windows-gnu')
158-
shell: pwsh
159-
run: |
160-
# Install MSYS2 and MinGW-w64
161-
choco install msys2 -y
162-
163-
# Update MSYS2 and install required packages
164-
C:\tools\msys64\usr\bin\bash.exe -lc "pacman -Syu --noconfirm"
165-
C:\tools\msys64\usr\bin\bash.exe -lc "pacman -S --noconfirm mingw-w64-x86_64-gcc mingw-w64-x86_64-openssl mingw-w64-x86_64-pkg-config perl"
166-
167-
# Add MinGW to PATH
168-
echo "C:\tools\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
169-
echo "C:\tools\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
77+
# Prepare binary with unique name
78+
if [[ "${{ matrix.build.TARGET }}" == *"windows"* ]]; then
79+
BINARY="gh-templates-${{ matrix.build.NAME }}.exe"
80+
cp target/${{ matrix.build.TARGET }}/release/gh-templates.exe $BINARY
81+
else
82+
BINARY="gh-templates-${{ matrix.build.NAME }}"
83+
cp target/${{ matrix.build.TARGET }}/release/gh-templates $BINARY
84+
chmod +x $BINARY
85+
fi
17086
171-
- name: Build (Windows)
172-
if: runner.os == 'Windows'
173-
shell: pwsh
174-
run: |
175-
# Set environment variables for MinGW builds
176-
if ("${{ matrix.build.TARGET }}" -like "*windows-gnu*") {
177-
$env:OPENSSL_DIR = "C:\tools\msys64\mingw64"
178-
$env:PKG_CONFIG_PATH = "C:\tools\msys64\mingw64\lib\pkgconfig"
179-
$env:PKG_CONFIG_ALLOW_CROSS = "1"
180-
$env:OPENSSL_STATIC = "1"
181-
# Use the MSYS2 Perl instead of Windows Perl
182-
$env:PATH = "C:\tools\msys64\usr\bin;C:\tools\msys64\mingw64\bin;" + $env:PATH
183-
}
184-
185-
# Build with retry mechanism for MinGW
186-
if ("${{ matrix.build.TARGET }}" -like "*windows-gnu*") {
187-
# Try building with native OpenSSL first
188-
try {
189-
cargo build --release --target ${{ matrix.build.TARGET }}
190-
} catch {
191-
Write-Host "First build attempt failed, trying with vendored OpenSSL..."
192-
$env:OPENSSL_STATIC = "1"
193-
$env:OPENSSL_VENDOR = "1"
194-
cargo build --release --target ${{ matrix.build.TARGET }} --features vendored-openssl
195-
}
196-
} else {
197-
cargo build --release --target ${{ matrix.build.TARGET }}
87+
echo "BINARY=$BINARY" >> $GITHUB_ENV
88+
89+
# Prepare npm + python packages (still generic inside folders)
90+
mkdir -p npm/bin python/gh_templates_bin
91+
cp $BINARY npm/bin/
92+
cp $BINARY python/gh_templates_bin/
93+
94+
# npm package.json
95+
cat > npm/package.json << EOF
96+
{
97+
"name": "@rafaeljohn9/gh-templates-${{ matrix.build.NAME }}",
98+
"version": "$VERSION",
99+
"bin": { "gh-templates": "./bin/$BINARY" },
100+
"files": ["bin/"],
101+
"license": "APACHE-2.0"
198102
}
199-
200-
# Set binary name and copy binary
201-
echo "BINARY_NAME=gh-templates.exe" >> $env:GITHUB_ENV
202-
Copy-Item "target/${{ matrix.build.TARGET }}/release/gh-templates.exe" .
103+
EOF
104+
105+
# Python setup.py
106+
cat > python/setup.py << EOF
107+
from setuptools import setup
108+
setup(
109+
name='gh-templates-${{ matrix.build.NAME }}',
110+
version='$VERSION',
111+
packages=['gh_templates_bin'],
112+
package_data={'gh_templates_bin': ['*']},
113+
entry_points={'console_scripts': ['gh-templates=gh_templates_bin:main']},
114+
license='APACHE-2.0'
115+
)
116+
EOF
117+
118+
# Python __init__.py
119+
cat > python/gh_templates_bin/__init__.py << 'EOF'
120+
import os, sys, subprocess
121+
def main():
122+
binary = os.path.join(os.path.dirname(__file__), os.getenv("BINARY", "gh-templates"))
123+
sys.exit(subprocess.run([binary] + sys.argv[1:]).returncode)
124+
EOF
203125
204126
- name: Upload to GitHub Release
205127
uses: softprops/action-gh-release@v2
206128
with:
207-
files: ${{ env.BINARY_NAME }}
129+
files: ${{ env.BINARY }}
130+
overwrite: true
131+
fail_on_unmatched_files: false
208132

133+
# (rest of your npm + PyPI steps remain unchanged below …)
209134
- name: Setup Node.js for NPM
210135
if: matrix.build.NPM_PUBLISH == true
211136
uses: actions/setup-node@v4
@@ -766,36 +691,31 @@ jobs:
766691

767692
- name: Update Homebrew formula
768693
run: |
769-
VERSION="${{ env.RELEASE_VERSION }}"
770-
771-
# Get release assets - use platform-specific URLs
772-
LINUX_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gh-templates"
773-
DARWIN_ARM_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gh-templates"
774-
DARWIN_X64_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gh-templates"
775-
694+
VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//')
695+
696+
# Get release assets
697+
LINUX_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gh-templates-linux-x64-glibc"
698+
DARWIN_ARM_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gh-templates-darwin-arm64"
699+
DARWIN_X64_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gh-templates-darwin-x64"
700+
776701
# Calculate checksums
777702
wget -q $LINUX_URL -O linux-binary
778703
wget -q $DARWIN_ARM_URL -O darwin-arm-binary
779704
wget -q $DARWIN_X64_URL -O darwin-x64-binary
780-
781705
LINUX_SHA=$(shasum -a 256 linux-binary | cut -d' ' -f1)
782706
DARWIN_ARM_SHA=$(shasum -a 256 darwin-arm-binary | cut -d' ' -f1)
783707
DARWIN_X64_SHA=$(shasum -a 256 darwin-x64-binary | cut -d' ' -f1)
784-
785-
# Clone homebrew tap using the PAT
786-
git clone https://rafaeljohn9:${{ secrets.HOMEBREW_GITHUB_TOKEN }}@github.com/rafaeljohn9/homebrew-tap.git
708+
709+
# Clone homebrew tap
710+
git clone https://github.com/rafaeljohn9/homebrew-tap.git
787711
cd homebrew-tap
788-
789-
# Create Formula directory if it doesn't exist
790-
mkdir -p Formula
791-
712+
792713
# Create/update formula
793714
cat > Formula/gh-templates.rb << EOF
794715
class GhTemplates < Formula
795716
desc "GitHub Templates CLI tool"
796717
homepage "https://github.com/${{ github.repository }}"
797718
version "$VERSION"
798-
799719
on_macos do
800720
if Hardware::CPU.arm?
801721
url "$DARWIN_ARM_URL"
@@ -805,12 +725,10 @@ jobs:
805725
sha256 "$DARWIN_X64_SHA"
806726
end
807727
end
808-
809728
on_linux do
810729
url "$LINUX_URL"
811730
sha256 "$LINUX_SHA"
812731
end
813-
814732
def install
815733
bin.install "gh-templates"
816734
end
@@ -820,17 +738,10 @@ jobs:
820738
end
821739
end
822740
EOF
823-
741+
824742
# Commit and push
825743
git config user.name "github-actions[bot]"
826744
git config user.email "github-actions[bot]@users.noreply.github.com"
827745
git add Formula/gh-templates.rb
828-
829-
# Check if this is the first commit
830-
if git rev-parse --verify HEAD >/dev/null 2>&1; then
831-
git commit -m "Update gh-templates to $VERSION"
832-
else
833-
git commit -m "Initial commit: Add gh-templates formula $VERSION"
834-
fi
835-
836-
git push
746+
git commit -m "Update gh-templates to $VERSION"
747+
git push https://x-access-token:${{ secrets.HOMEBREW_GITHUB_TOKEN }}@github.com/rafaeljohn9/homebrew-tap.git

src/commands/gitignore/add.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ fn download_templates(
209209
} else if output.len() == templates.len() {
210210
// Save each template to its own file as specified in output
211211
for (template_name, output_file) in templates.iter().zip(output.iter()) {
212+
// check if the template_name has a .gitignore ext rm it to normalize it
213+
let template_name = template_name.strip_suffix(".gitignore").unwrap_or(template_name);
212214
let template_path = find_template_in_cache(template_name, cache)?;
213215
let url = format!("{}/{}", GITHUB_RAW_BASE, template_path);
214216

src/commands/gitignore/preview.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ impl super::Runnable for PreviewArgs {
3636
}
3737

3838
fn preview_single_template(template: &str, cache: &super::Cache<String>) -> anyhow::Result<()> {
39+
// normalize template if it has the .gitignore ext
40+
let template = template.strip_suffix(".gitignore").unwrap_or(template);
41+
3942
// Find the template path in cache
4043
let template_path = find_template_in_cache(template, cache)?;
4144

0 commit comments

Comments
 (0)