Skip to content

Commit 165ba04

Browse files
committed
Refactor GitHub Actions workflows to use a common build process and update domain in docs deployment
1 parent 8c7aa49 commit 165ba04

File tree

6 files changed

+126
-87
lines changed

6 files changed

+126
-87
lines changed

.github/workflows/common-build.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Common Build Steps
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
rust_target:
7+
description: 'Rust target triple'
8+
required: false
9+
type: string
10+
default: ''
11+
run_tests:
12+
description: 'Whether to run tests'
13+
required: false
14+
type: boolean
15+
default: true
16+
outputs:
17+
version:
18+
description: "Version extracted from the release tag"
19+
value: ${{ jobs.build.outputs.version }}
20+
21+
jobs:
22+
build:
23+
name: Build
24+
runs-on: ${{ inputs.os || 'ubuntu-latest' }}
25+
outputs:
26+
version: ${{ steps.version.outputs.version }}
27+
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- name: Install Rust
32+
uses: actions-rs/toolchain@v1
33+
with:
34+
profile: minimal
35+
toolchain: stable
36+
override: true
37+
target: ${{ inputs.rust_target }}
38+
39+
- name: Build
40+
run: |
41+
if [ -n "${{ inputs.rust_target }}" ]; then
42+
cargo build --release --target ${{ inputs.rust_target }}
43+
else
44+
cargo build --release
45+
fi
46+
47+
- name: Run tests
48+
if: inputs.run_tests
49+
run: |
50+
if [ -n "${{ inputs.rust_target }}" ]; then
51+
cargo test --release --target ${{ inputs.rust_target }}
52+
else
53+
cargo test --release
54+
fi
55+
56+
- name: Extract version
57+
id: version
58+
run: |
59+
VERSION=${GITHUB_REF#refs/tags/v}
60+
echo "version=$VERSION" >> $GITHUB_OUTPUT

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ jobs:
3535
publish_dir: ./docs/book/book
3636
publish_branch: gh-pages
3737
force_orphan: true
38-
cname: rustyhook.com # Optional: Set a custom domain
38+
cname: rustyhook.dev

.github/workflows/publish-brew.yml

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,58 @@ on:
55
types: [created]
66

77
jobs:
8-
build-and-publish:
9-
name: Build and publish to Homebrew
8+
build:
9+
uses: ./.github/workflows/common-build.yml
10+
with:
11+
rust_target: x86_64-apple-darwin
12+
run_tests: false
13+
14+
publish:
15+
name: Publish to Homebrew
1016
runs-on: macos-latest
11-
17+
needs: build
18+
1219
steps:
1320
- uses: actions/checkout@v3
14-
15-
- name: Install Rust
16-
uses: actions-rs/toolchain@v1
17-
with:
18-
profile: minimal
19-
toolchain: stable
20-
override: true
21-
target: x86_64-apple-darwin
22-
23-
- name: Build
24-
run: cargo build --release --target x86_64-apple-darwin
25-
21+
2622
- name: Install Homebrew
2723
run: |
2824
brew update
29-
25+
3026
- name: Calculate SHA256
3127
id: sha
3228
run: |
33-
VERSION=${GITHUB_REF#refs/tags/v}
29+
VERSION="${{ needs.build.outputs.version }}"
3430
echo "version=$VERSION" >> $GITHUB_OUTPUT
35-
31+
3632
# Create a tarball of the binary
3733
mkdir -p target/packages
3834
tar -czf target/packages/rustyhook-$VERSION-x86_64-apple-darwin.tar.gz -C target/x86_64-apple-darwin/release rh
39-
35+
4036
# Calculate SHA256
4137
CHECKSUM=$(shasum -a 256 target/packages/rustyhook-$VERSION-x86_64-apple-darwin.tar.gz | awk '{print $1}')
4238
echo "sha256=$CHECKSUM" >> $GITHUB_OUTPUT
43-
39+
4440
- name: Prepare Homebrew formula
4541
run: |
4642
VERSION=${{ steps.sha.outputs.version }}
4743
SHA256=${{ steps.sha.outputs.sha256 }}
48-
44+
4945
# Create formula directory
5046
mkdir -p homebrew-rustyhook
51-
47+
5248
# Copy and update formula
5349
cp packaging/homebrew/rustyhook.rb homebrew-rustyhook/rustyhook.rb
54-
50+
5551
# Update version and SHA256
5652
sed -i '' "s/version \".*\"/version \"$VERSION\"/" homebrew-rustyhook/rustyhook.rb
5753
sed -i '' "s/sha256 \".*\"/sha256 \"$SHA256\"/" homebrew-rustyhook/rustyhook.rb
58-
54+
5955
- name: Setup Git
6056
run: |
6157
git config --global user.name "GitHub Actions"
6258
git config --global user.email "actions@github.com"
63-
59+
6460
- name: Create or update Homebrew tap repository
6561
run: |
6662
# Clone the tap repository if it exists, or create a new one
@@ -72,17 +68,17 @@ jobs:
7268
git init
7369
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository_owner }}/homebrew-rustyhook.git
7470
fi
75-
71+
7672
# Copy the formula
7773
cp ../homebrew-rustyhook/rustyhook.rb ./Formula/rustyhook.rb
78-
74+
7975
# Commit and push
8076
git add Formula/rustyhook.rb
8177
git commit -m "Update rustyhook to ${{ steps.sha.outputs.version }}"
8278
git push -u origin main
83-
79+
8480
- name: Upload artifacts
8581
uses: actions/upload-artifact@v3
8682
with:
8783
name: homebrew-formula
88-
path: homebrew-rustyhook/
84+
path: homebrew-rustyhook/

.github/workflows/publish-cargo.yml

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,35 @@ on:
55
types: [created]
66

77
jobs:
8-
build-and-publish:
9-
name: Build and publish to crates.io
8+
build:
9+
uses: ./.github/workflows/common-build.yml
10+
with:
11+
run_tests: true
12+
13+
publish:
14+
name: Publish to crates.io
1015
runs-on: ubuntu-latest
11-
16+
needs: build
17+
1218
steps:
1319
- uses: actions/checkout@v3
14-
15-
- name: Install Rust
16-
uses: actions-rs/toolchain@v1
17-
with:
18-
profile: minimal
19-
toolchain: stable
20-
override: true
21-
22-
- name: Build
23-
run: cargo build --release
24-
25-
- name: Run tests
26-
run: cargo test --release
27-
28-
- name: Extract version
29-
id: version
30-
run: |
31-
VERSION=${GITHUB_REF#refs/tags/v}
32-
echo "version=$VERSION" >> $GITHUB_OUTPUT
33-
20+
3421
- name: Verify Cargo.toml version
3522
run: |
3623
CARGO_VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
37-
if [ "$CARGO_VERSION" != "${{ steps.version.outputs.version }}" ]; then
38-
echo "Error: Version in Cargo.toml ($CARGO_VERSION) does not match release tag (${{ steps.version.outputs.version }})"
24+
if [ "$CARGO_VERSION" != "${{ needs.build.outputs.version }}" ]; then
25+
echo "Error: Version in Cargo.toml ($CARGO_VERSION) does not match release tag (${{ needs.build.outputs.version }})"
3926
exit 1
4027
fi
41-
28+
4229
- name: Login to crates.io
4330
uses: actions-rs/cargo@v1
4431
with:
4532
command: login
4633
args: ${{ secrets.CRATES_IO_TOKEN }}
47-
34+
4835
- name: Publish to crates.io
4936
uses: actions-rs/cargo@v1
5037
with:
5138
command: publish
52-
args: --no-verify
39+
args: --no-verify

.github/workflows/publish-winget.yml

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,50 @@ on:
55
types: [created]
66

77
jobs:
8-
build-and-publish:
9-
name: Build and publish to WinGet
8+
build:
9+
uses: ./.github/workflows/common-build.yml
10+
with:
11+
rust_target: x86_64-pc-windows-msvc
12+
run_tests: false
13+
14+
publish:
15+
name: Publish to WinGet
1016
runs-on: windows-latest
11-
17+
needs: build
18+
1219
steps:
1320
- uses: actions/checkout@v3
14-
15-
- name: Install Rust
16-
uses: actions-rs/toolchain@v1
17-
with:
18-
profile: minimal
19-
toolchain: stable
20-
override: true
21-
target: x86_64-pc-windows-msvc
22-
23-
- name: Build
24-
run: cargo build --release --target x86_64-pc-windows-msvc
25-
21+
2622
- name: Calculate hash and prepare package
2723
id: package
2824
shell: pwsh
2925
run: |
30-
$VERSION = $env:GITHUB_REF -replace 'refs/tags/v', ''
26+
$VERSION = "${{ needs.build.outputs.version }}"
3127
echo "version=$VERSION" >> $env:GITHUB_OUTPUT
32-
28+
3329
# Create a zip of the binary
3430
New-Item -ItemType Directory -Path target/packages -Force
3531
Compress-Archive -Path target/x86_64-pc-windows-msvc/release/rh.exe -DestinationPath target/packages/rustyhook-v$VERSION-x86_64-pc-windows-msvc.zip
36-
32+
3733
# Calculate SHA256
3834
$HASH = (Get-FileHash -Path target/packages/rustyhook-v$VERSION-x86_64-pc-windows-msvc.zip -Algorithm SHA256).Hash.ToLower()
3935
echo "sha256=$HASH" >> $env:GITHUB_OUTPUT
40-
36+
4137
- name: Prepare WinGet manifest
4238
id: manifest
4339
shell: pwsh
4440
run: |
4541
$VERSION = "${{ steps.package.outputs.version }}"
4642
$HASH = "${{ steps.package.outputs.sha256 }}"
4743
$REPO_OWNER = "${{ github.repository_owner }}"
48-
44+
4945
# Create winget directory
5046
New-Item -ItemType Directory -Path winget-manifest -Force
5147
New-Item -ItemType Directory -Path winget-manifest/RustyHook.RustyHook/$VERSION -Force
52-
48+
5349
# Copy and update manifest
5450
Copy-Item -Path packaging/winget/rustyhook.yaml -Destination winget-manifest/RustyHook.RustyHook/$VERSION/RustyHook.RustyHook.yaml
55-
51+
5652
# Update version, URL, and hash in the manifest
5753
$manifestPath = "winget-manifest/RustyHook.RustyHook/$VERSION/RustyHook.RustyHook.yaml"
5854
$manifestContent = Get-Content -Path $manifestPath -Raw
@@ -62,15 +58,15 @@ jobs:
6258
$manifestContent = $manifestContent -replace 'InstallerUrl: .*', "InstallerUrl: https://github.com/$REPO_OWNER/rustyhook/releases/download/v$VERSION/rustyhook-v$VERSION-x86_64-pc-windows-msvc.zip"
6359
$manifestContent = $manifestContent -replace 'InstallerSha256: .*', "InstallerSha256: $HASH"
6460
Set-Content -Path $manifestPath -Value $manifestContent
65-
61+
6662
echo "manifest_path=winget-manifest" >> $env:GITHUB_OUTPUT
67-
63+
6864
- name: Upload artifacts
6965
uses: actions/upload-artifact@v3
7066
with:
7167
name: winget-manifest
7268
path: ${{ steps.manifest.outputs.manifest_path }}
73-
69+
7470
- name: Create PR to WinGet repository
7571
uses: peter-evans/create-pull-request@v5
7672
with:
@@ -85,12 +81,11 @@ jobs:
8581
title: "Add RustyHook version ${{ steps.package.outputs.version }}"
8682
body: |
8783
This PR adds the RustyHook package version ${{ steps.package.outputs.version }} to the WinGet repository.
88-
84+
8985
- Package: RustyHook
9086
- Version: ${{ steps.package.outputs.version }}
9187
- Publisher: RustyHook Team
92-
88+
9389
This is an automated PR created by the GitHub Actions workflow.
9490
draft: false
9591
base: master
96-
repository: microsoft/winget-pkgs

docs/plan.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Tasks:
55
- [x] create documentation for the project that can be pushed to github pages using a github action
66
- [x] create a github action to publish the documentation to github pages
77
- [x] Update the README to include a section on how to convert from pre-commit to rustyhook
8+
- [x] Remove the duplicate code in the github actions by consolidating the build steps and deployment steps into a single workflow (the ones that relate to publishing that is)
89
- [ ] create a command line tool that can be used to convert a pre-commit configuration file to rustyhook configuration file
910
- [ ] expand all built in hooks to include all known hooks from https://pre-commit.com/hooks.html
1011
- [ ] enable logging to a file or other outputs other than just stdout
@@ -14,7 +15,7 @@ Tasks:
1415
- [ ] emulate all known pre-commit hooks for use with native execution - all known hooks at https://github.com/pre-commit/pre-commit-hooks
1516
- [ ] create tests for each hook and complete coverage
1617
- [ ] replace the npm and nvm install process with fnm if it makes sense to do so
17-
- [ ] Remove the duplicate code in the github actions by consolidating the build steps and deployment steps into a single workflow
18+
1819
- [ ] Re-evaluate the use of python and other languages in the docker file as they are likely not needed
1920
- [ ] Update the `.junie/guidelines.md` file to include the new features and rust best practices
2021
- [ ] Use a mechanism to create and deploy semver compatible releases. Perhaps use cargo-release or some other mechanism to automatically generate release notes and create a tag - trigger a release on tag creation.

0 commit comments

Comments
 (0)