1+ name : Release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*'
7+
8+ env :
9+ CARGO_TERM_COLOR : always
10+
11+ jobs :
12+ create-release :
13+ name : Create Release
14+ runs-on : ubuntu-latest
15+ outputs :
16+ upload_url : ${{ steps.create_release.outputs.upload_url }}
17+ steps :
18+ - name : Create Release
19+ id : create_release
20+ uses : actions/create-release@v1
21+ env :
22+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
23+ with :
24+ tag_name : ${{ github.ref }}
25+ release_name : Release ${{ github.ref }}
26+ draft : false
27+ prerelease : false
28+
29+ build-release :
30+ name : Build Release
31+ needs : create-release
32+ strategy :
33+ matrix :
34+ include :
35+ # Linux
36+ - os : ubuntu-latest
37+ target : x86_64-unknown-linux-gnu
38+ artifact_name : diffscope
39+ asset_name : diffscope-x86_64-unknown-linux-gnu
40+ - os : ubuntu-latest
41+ target : x86_64-unknown-linux-musl
42+ artifact_name : diffscope
43+ asset_name : diffscope-x86_64-unknown-linux-musl
44+ - os : ubuntu-latest
45+ target : aarch64-unknown-linux-gnu
46+ artifact_name : diffscope
47+ asset_name : diffscope-aarch64-unknown-linux-gnu
48+
49+ # macOS
50+ - os : macos-latest
51+ target : x86_64-apple-darwin
52+ artifact_name : diffscope
53+ asset_name : diffscope-x86_64-apple-darwin
54+ - os : macos-latest
55+ target : aarch64-apple-darwin
56+ artifact_name : diffscope
57+ asset_name : diffscope-aarch64-apple-darwin
58+
59+ # Windows
60+ - os : windows-latest
61+ target : x86_64-pc-windows-msvc
62+ artifact_name : diffscope.exe
63+ asset_name : diffscope-x86_64-pc-windows-msvc.exe
64+
65+ runs-on : ${{ matrix.os }}
66+
67+ steps :
68+ - name : Checkout code
69+ uses : actions/checkout@v4
70+
71+ - name : Install Rust
72+ uses : dtolnay/rust-toolchain@stable
73+ with :
74+ targets : ${{ matrix.target }}
75+
76+ - name : Install cross-compilation tools
77+ if : matrix.target == 'aarch64-unknown-linux-gnu'
78+ run : |
79+ sudo apt-get update
80+ sudo apt-get install -y gcc-aarch64-linux-gnu
81+
82+ - name : Install musl tools
83+ if : matrix.target == 'x86_64-unknown-linux-musl'
84+ run : |
85+ sudo apt-get update
86+ sudo apt-get install -y musl-tools
87+
88+ - name : Build
89+ run : cargo build --release --target ${{ matrix.target }}
90+
91+ - name : Strip binary (Linux and macOS)
92+ if : matrix.os != 'windows-latest'
93+ run : |
94+ strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
95+
96+ - name : Upload Release Asset
97+ uses : actions/upload-release-asset@v1
98+ env :
99+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
100+ with :
101+ upload_url : ${{ needs.create-release.outputs.upload_url }}
102+ asset_path : target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
103+ asset_name : ${{ matrix.asset_name }}
104+ asset_content_type : application/octet-stream
105+
106+ build-docker :
107+ name : Build and Push Docker Image
108+ runs-on : ubuntu-latest
109+ steps :
110+ - name : Checkout code
111+ uses : actions/checkout@v4
112+
113+ - name : Set up QEMU
114+ uses : docker/setup-qemu-action@v3
115+
116+ - name : Set up Docker Buildx
117+ uses : docker/setup-buildx-action@v3
118+
119+ - name : Login to GitHub Container Registry
120+ uses : docker/login-action@v3
121+ with :
122+ registry : ghcr.io
123+ username : ${{ github.actor }}
124+ password : ${{ secrets.GITHUB_TOKEN }}
125+
126+ - name : Extract version from tag
127+ id : get_version
128+ run : echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
129+
130+ - name : Build and push Docker image
131+ uses : docker/build-push-action@v5
132+ with :
133+ context : .
134+ platforms : linux/amd64,linux/arm64
135+ push : true
136+ tags : |
137+ ghcr.io/haasonsaas/diffscope:latest
138+ ghcr.io/haasonsaas/diffscope:${{ steps.get_version.outputs.VERSION }}
139+
140+ update-homebrew :
141+ name : Update Homebrew Formula
142+ needs : build-release
143+ runs-on : ubuntu-latest
144+ steps :
145+ - name : Checkout tap repository
146+ uses : actions/checkout@v4
147+ with :
148+ repository : haasonsaas/homebrew-diffscope
149+ token : ${{ secrets.HOMEBREW_TAP_TOKEN }}
150+
151+ - name : Update formula
152+ run : |
153+ VERSION=${GITHUB_REF#refs/tags/v}
154+ sed -i "s/version \".*\"/version \"$VERSION\"/" Formula/diffscope.rb
155+
156+ # Calculate SHA256 for x86_64 macOS binary
157+ DARWIN_X64_URL="https://github.com/haasonsaas/diffscope/releases/download/v${VERSION}/diffscope-x86_64-apple-darwin"
158+ DARWIN_X64_SHA=$(curl -sL $DARWIN_X64_URL | shasum -a 256 | cut -d' ' -f1)
159+
160+ # Calculate SHA256 for ARM64 macOS binary
161+ DARWIN_ARM64_URL="https://github.com/haasonsaas/diffscope/releases/download/v${VERSION}/diffscope-aarch64-apple-darwin"
162+ DARWIN_ARM64_SHA=$(curl -sL $DARWIN_ARM64_URL | shasum -a 256 | cut -d' ' -f1)
163+
164+ # Update the formula with new checksums
165+ # This is a simplified example - you'd need to update the actual formula structure
166+ echo "Updated version to $VERSION"
167+
168+ - name : Commit and push changes
169+ run : |
170+ git config user.name github-actions
171+ git config user.email github-actions@github.com
172+ git add Formula/diffscope.rb
173+ git commit -m "Update diffscope to ${GITHUB_REF#refs/tags/}"
174+ git push
0 commit comments