Skip to content

Commit 9600542

Browse files
committed
feat: Create unified release workflow
1 parent a92519a commit 9600542

File tree

3 files changed

+121
-16
lines changed

3 files changed

+121
-16
lines changed

.github/workflows/release.yml

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,114 @@
1-
name: Create GitHub Release
1+
name: Create Unified Release
22

33
on:
44
push:
55
tags:
6-
- 'v*' # Trigger this workflow on tags like v0.1.0, v1.2.3, etc.
6+
- 'v*'
77

88
jobs:
9-
build-and-release:
9+
create-release:
1010
runs-on: ubuntu-latest
1111
permissions:
1212
contents: write
13+
outputs:
14+
upload_url: ${{ steps.create_release.outputs.upload_url }}
15+
release_id: ${{ steps.create_release.outputs.id }}
1316
steps:
1417
- name: Check out code
15-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1619
with:
17-
# Fetch all history so we can generate notes from the previous tag
1820
fetch-depth: 0
1921

2022
- name: Generate Release Notes
2123
id: release_notes
2224
run: |
23-
# Make the script executable
2425
chmod +x ./scripts/generate_release_notes.sh
25-
# Run the script and store its output. The output is captured by using
26-
# a special GitHub Actions syntax to set the step's output variable.
2726
NOTES=$(./scripts/generate_release_notes.sh)
28-
# This is a bit of a hack to make the multiline notes work in the next step
2927
NOTES="${NOTES//'%'/'%25'}"
3028
NOTES="${NOTES//$'\n'/'%0A'}"
3129
NOTES="${NOTES//$'\r'/'%0D'}"
3230
echo "notes=$NOTES" >> $GITHUB_OUTPUT
3331
34-
- name: Create Release
32+
- name: Create Draft Release
33+
id: create_release
3534
uses: softprops/action-gh-release@v1
3635
with:
37-
# The GITHUB_TOKEN is a secret automatically provided by GitHub Actions
38-
# so you don't have to create it manually. It has permissions to
39-
# create releases in your repository.
4036
token: ${{ secrets.GITHUB_TOKEN }}
4137
body: ${{ steps.release_notes.outputs.notes }}
4238
name: Release ${{ github.ref_name }}
43-
draft: false
39+
draft: true # Create a draft first
4440
prerelease: false
41+
42+
build-and-upload:
43+
runs-on: ubuntu-latest
44+
needs: create-release
45+
steps:
46+
- name: Check out code
47+
uses: actions/checkout@v4
48+
- name: Install Go
49+
uses: actions/setup-go@v5
50+
with:
51+
go-version: '1.22'
52+
53+
- name: Build the Debian package
54+
run: |
55+
chmod +x ./scripts/build_packages.sh
56+
bash ./scripts/build_packages.sh ${{ github.ref_name }}
57+
58+
- name: Upload Debian package to draft release
59+
uses: actions/upload-release-asset@v1
60+
with:
61+
upload_url: ${{ needs.create-release.outputs.upload_url }}
62+
asset_path: ./docker-ai_${{ github.ref_name }}_amd64.deb
63+
asset_name: docker-ai_${{ github.ref_name }}_amd64.deb
64+
asset_content_type: application/vnd.debian.binary-package
4565
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
68+
update-homebrew-tap:
69+
runs-on: ubuntu-latest
70+
needs: build-and-upload
71+
steps:
72+
- name: Checkout Homebrew tap repository
73+
uses: actions/checkout@v4
74+
with:
75+
repository: Aj7Ay/homebrew-tap
76+
token: ${{ secrets.PAT_FOR_HOMEBREW_TAP }}
77+
path: homebrew-tap
78+
79+
- name: Calculate SHA256 of the new release tarball
80+
id: shasum
81+
run: |
82+
RELEASE_URL="https://github.com/${{ github.repository }}/archive/refs/tags/${{ github.ref_name }}.tar.gz"
83+
SHA256=$(curl -L $RELEASE_URL | shasum -a 256 | cut -d' ' -f1)
84+
echo "sha256=${SHA256}" >> $GITHUB_ENV
85+
86+
- name: Update Homebrew formula
87+
run: |
88+
cd homebrew-tap
89+
sed -i "s|url \".*\"|url \"https://github.com/${{ github.repository }}/archive/refs/tags/${{ github.ref_name }}.tar.gz\"|" docker-ai.rb
90+
sed -i "s/sha256 \".*\"/sha256 \"${{ env.sha256 }}\"/" docker-ai.rb
91+
92+
- name: Commit and push changes
93+
run: |
94+
cd homebrew-tap
95+
git config --global user.name 'github-actions[bot]'
96+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
97+
git add docker-ai.rb
98+
if git diff --staged --quiet; then
99+
echo "No changes to the formula to commit."
100+
else
101+
git commit -m "Update docker-ai to ${{ github.ref_name }}"
102+
git push
103+
fi
104+
105+
publish-release:
106+
runs-on: ubuntu-latest
107+
needs: update-homebrew-tap
108+
steps:
109+
- name: Publish the release
110+
uses: softprops/action-gh-release@v1
111+
with:
112+
token: ${{ secrets.GITHUB_TOKEN }}
113+
id: ${{ needs.create-release.outputs.release_id }}
114+
draft: false # This publishes the release

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
.idea/
1616
.vscode/
1717
*.swp
18-
.DS_Store
18+
.DS_Store
19+
.env
20+
homebrew-tap/

scripts/build_packages.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# This script builds the debian package.
5+
# The VERSION argument is passed from the GitHub workflow.
6+
VERSION=${1#v} # a v prefix from the tag
7+
8+
if [ -z "$VERSION" ]; then
9+
echo "Usage: $0 <version>"
10+
exit 1
11+
fi
12+
13+
# Create the package structure
14+
DEB_DIR="docker-ai_${VERSION}_amd64"
15+
mkdir -p "$DEB_DIR/usr/local/bin"
16+
mkdir -p "$DEB_DIR/DEBIAN"
17+
18+
# Build the Go binary
19+
echo "Building docker-ai for Linux..."
20+
GOOS=linux GOARCH=amd64 go build -o "$DEB_DIR/usr/local/bin/docker-ai" ./cmd/docker-ai
21+
22+
# Create the debian control file
23+
cat > "$DEB_DIR/DEBIAN/control" <<EOF
24+
Package: docker-ai
25+
Version: $VERSION
26+
Architecture: amd64
27+
Maintainer: Ajay <[email protected]>
28+
Description: An AI-powered CLI for Docker.
29+
EOF
30+
31+
# Build the .deb package
32+
echo "Building Debian package..."
33+
dpkg-deb --build "$DEB_DIR"
34+
35+
echo "Package created: ${DEB_DIR}.deb"

0 commit comments

Comments
 (0)