1
+ name : Build and Release
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - master
7
+ tags :
8
+ - " v*"
9
+
10
+ jobs :
11
+ build :
12
+ name : Build and Release Rust Binary
13
+ runs-on : ${{ matrix.os }}
14
+
15
+ permissions :
16
+ contents : write
17
+ packages : write
18
+
19
+ strategy :
20
+ matrix :
21
+ os : [ubuntu-latest, macos-latest]
22
+ include :
23
+ - os : macos-latest
24
+ target_x86 : x86_64-apple-darwin
25
+ target_arm : aarch64-apple-darwin
26
+ - os : ubuntu-latest
27
+ target : x86_64-unknown-linux-gnu
28
+
29
+ steps :
30
+ - name : Checkout code
31
+ uses : actions/checkout@v3
32
+ with :
33
+ fetch-depth : 5
34
+
35
+ - name : Install Rust
36
+ uses : actions-rs/toolchain@v1
37
+ with :
38
+ toolchain : stable
39
+ target : ${{ matrix.target || matrix.target_x86 }}
40
+
41
+ - name : Add macOS universal binary targets
42
+ if : matrix.os == 'macos-latest'
43
+ run : |
44
+ rustup target add x86_64-apple-darwin aarch64-apple-darwin
45
+
46
+ - name : Add Linux and Windows targets
47
+ if : matrix.os != 'macos-latest'
48
+ run : rustup target add ${{ matrix.target }}
49
+
50
+ - name : Build with Cargo
51
+ run : |
52
+ if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
53
+ cargo build --release --target ${{ matrix.target_x86 }}
54
+ cargo build --release --target ${{ matrix.target_arm }}
55
+ lipo -create -output ./target/release/universal_binary \
56
+ ./target/${{ matrix.target_x86 }}/release/duplicate-checker \
57
+ ./target/${{ matrix.target_arm }}/release/duplicate-checker
58
+ else
59
+ cargo build --release --target ${{ matrix.target }}
60
+ fi
61
+ shell : bash
62
+
63
+ - name : Set prerelease flag
64
+ id : prerelease_check
65
+ run : |
66
+ if [[ "${GITHUB_REF#refs/tags/}" == *"alpha"* || "${GITHUB_REF#refs/tags/}" == *"beta"* ]]; then
67
+ echo "prerelease=true" >> $GITHUB_ENV
68
+ else
69
+ echo "prerelease=false" >> $GITHUB_ENV
70
+ fi
71
+
72
+ - name : Check if release exists
73
+ id : check_release
74
+ run : |
75
+ if gh release view "${GITHUB_REF_NAME}" &>/dev/null; then
76
+ echo "release_exists=true" >> $GITHUB_ENV
77
+ else
78
+ echo "release_exists=false" >> $GITHUB_ENV
79
+ fi
80
+ env :
81
+ GITHUB_TOKEN : ${{ secrets.PAT_TOKEN }}
82
+
83
+ - name : Create a GitHub Release
84
+ if : env.release_exists == 'false'
85
+ id : create_release
86
+ uses : actions/create-release@v1
87
+ with :
88
+ tag_name : ${{ github.ref_name }}
89
+ release_name : Release ${{ github.ref_name }}
90
+ body : |
91
+ This release includes the latest Rust binary for version ${{ github.ref_name }}.
92
+ draft : false
93
+ prerelease : ${{ env.prerelease }}
94
+ env :
95
+ GITHUB_TOKEN : ${{ secrets.PAT_TOKEN }}
96
+
97
+ - name : Set upload URL for existing or new release
98
+ run : |
99
+ if [[ "${{ env.release_exists }}" == "true" ]]; then
100
+ UPLOAD_URL=$(gh api repos/${{ github.repository }}/releases/tags/${GITHUB_REF_NAME} --jq ".upload_url" | sed '')
101
+ else
102
+ UPLOAD_URL="${{ steps.create_release.outputs.upload_url }}"
103
+ fi
104
+ echo "upload_url=$UPLOAD_URL" >> $GITHUB_ENV
105
+ env :
106
+ GITHUB_TOKEN : ${{ secrets.PAT_TOKEN }}
107
+
108
+ - name : Check if macOS binary exists
109
+ if : matrix.os == 'macos-latest'
110
+ run : ls -la ./target/release/universal_binary
111
+
112
+ - name : Upload macOS Universal Binary Release Asset
113
+ if : matrix.os == 'macos-latest'
114
+ uses : actions/upload-release-asset@v1
115
+ with :
116
+ upload_url : ${{ env.upload_url }}
117
+ asset_path : ./target/release/universal_binary
118
+ asset_name : duplicate-checker-macos
119
+ asset_content_type : application/octet-stream
120
+ env :
121
+ GITHUB_TOKEN : ${{ secrets.PAT_TOKEN }}
122
+
123
+ - name : Upload Linux Release Asset
124
+ if : matrix.os == 'ubuntu-latest'
125
+ uses : actions/upload-release-asset@v1
126
+ with :
127
+ upload_url : ${{ env.upload_url }}
128
+ asset_path : ./target/${{ matrix.target }}/release/duplicate-checker
129
+ asset_name : duplicate-checker-linux
130
+ asset_content_type : application/octet-stream
131
+ env :
132
+ GITHUB_TOKEN : ${{ secrets.PAT_TOKEN }}
133
+
134
+ - name : Calculate SHA256 for macOS release asset
135
+ if : matrix.os == 'macos-latest'
136
+ id : calculate_sha
137
+ run : |
138
+ SHA256=$(shasum -a 256 ./target/release/universal_binary | awk '{print $1}')
139
+ echo "sha256=$SHA256" >> $GITHUB_ENV
140
+
141
+ - name : Trigger Homebrew Formula Update via cURL
142
+ if : matrix.os == 'macos-latest'
143
+ run : |
144
+ URL="https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/duplicate-checker-macos"
145
+ JSON_PAYLOAD=$(jq -n --arg url "$URL" '{"event_type": "update-duplicate-checker-formula", "client_payload": {"tag": "${{ github.ref_name }}", "download_url": $url, "sha": "${{ env.sha256 }}"}}')
146
+ echo "Payload: $JSON_PAYLOAD"
147
+ curl -L \
148
+ -X POST \
149
+ -H "Accept: application/vnd.github+json" \
150
+ -H "Authorization: Bearer ${{ secrets.PAT_TOKEN }}" \
151
+ -H "X-GitHub-Api-Version: 2022-11-28" \
152
+ https://api.github.com/repos/keaz/homebrew-homebrew/dispatches \
153
+ -d "$JSON_PAYLOAD"
154
+
0 commit comments