forked from ainame/xcodeproj-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
219 lines (185 loc) · 7.46 KB
/
release.yml
File metadata and controls
219 lines (185 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: Release
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 0.0.2)'
required: true
type: string
permissions:
contents: write
env:
PRODUCT_NAME: xcodeproj
jobs:
build-and-release:
name: Build Universal Binaries and Release
runs-on: macos-15
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Xcode
run: sudo xcode-select -s /Applications/Xcode_16.4.app/Contents/Developer
- name: Get version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Install Swiftly for Linux cross-compilation
run: |
# Install Swiftly using the official macOS method to user directory
curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg
installer -pkg swiftly.pkg -target CurrentUserHomeDirectory
rm swiftly.pkg
# Add to PATH for current session
echo "$HOME/.swiftly/bin" >> $GITHUB_PATH
export PATH="$HOME/.swiftly/bin:$PATH"
- name: Build Linux binaries
run: ./scripts/build-linux.sh
- name: Clean build directory before macOS build
run: rm -rf .build
- name: Build macOS binaries
run: ./scripts/build-macos.sh
- name: Test Binaries
run: |
# Test macOS binary
chmod +x build/macos/universal/${{ env.PRODUCT_NAME }}
build/macos/universal/${{ env.PRODUCT_NAME }} --version
build/macos/universal/${{ env.PRODUCT_NAME }} --help
# Test Linux binaries
chmod +x build/linux/x86_64/${{ env.PRODUCT_NAME }}
chmod +x build/linux/aarch64/${{ env.PRODUCT_NAME }}
- name: Update Homebrew Formula
run: |
./scripts/prepare-homebrew.sh "${{ steps.version.outputs.version }}" \
"build/macos/${{ env.PRODUCT_NAME }}-${{ steps.version.outputs.version }}-macos-universal.tar.gz"
- name: Commit Formula Update
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add Formula/xcodeproj.rb
git commit -m "chore: update Formula for ${{ steps.version.outputs.version }}" || echo "No changes to commit"
git push origin HEAD:main || echo "Failed to push changes"
- name: Create Release and Upload All Assets
env:
GH_TOKEN: ${{ github.token }}
run: |
# Determine if prerelease
PRERELEASE_FLAG=""
if [[ "${{ steps.version.outputs.version }}" == *"alpha"* ]] || [[ "${{ steps.version.outputs.version }}" == *"beta"* ]] || [[ "${{ steps.version.outputs.version }}" == *"rc"* ]]; then
PRERELEASE_FLAG="--prerelease"
fi
# Create release with all assets (macOS + Linux)
gh release create "${{ steps.version.outputs.version }}" \
--title "xcodeproj CLI ${{ steps.version.outputs.version }}" \
--notes "" \
$PRERELEASE_FLAG \
build/macos/universal/${{ env.PRODUCT_NAME }} \
build/macos/${{ env.PRODUCT_NAME }}-${{ steps.version.outputs.version }}-macos-universal.tar.gz \
build/macos/${{ env.PRODUCT_NAME }}-${{ steps.version.outputs.version }}-macos-checksums.txt \
build/linux/${{ env.PRODUCT_NAME }}-${{ steps.version.outputs.version }}-linux-x86_64.tar.gz \
build/linux/${{ env.PRODUCT_NAME }}-${{ steps.version.outputs.version }}-linux-aarch64.tar.gz \
build/linux/${{ env.PRODUCT_NAME }}-${{ steps.version.outputs.version }}-linux-checksums.txt
publish-npm:
name: Publish to npm
needs: build-and-release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# Fetch the latest to get any formula updates
fetch-depth: 0
- name: Pull latest changes
run: |
git pull origin main || true
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Get version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Publish npm package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
# Check if version already exists on npm
VERSION="${{ steps.version.outputs.version }}"
if npm view "@ainame/xcodeproj-cli@$VERSION" version 2>/dev/null; then
echo "Version $VERSION already published to npm, skipping..."
else
echo "Publishing version $VERSION to npm..."
npm publish --access public
fi
test-linux-after-publish:
name: Test Linux Compatibility (Post-Publish)
needs: publish-npm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Wait for npm package propagation
run: |
echo "Waiting for npm package to propagate..."
VERSION="${{ steps.version.outputs.version }}"
# Wait up to 5 minutes for the package to be available
for i in {1..30}; do
if npm view "@ainame/xcodeproj-cli@$VERSION" version 2>/dev/null; then
echo "Package version $VERSION is now available on npm"
break
else
echo "Waiting for package to be available... (attempt $i/30)"
sleep 10
fi
done
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Run Native Linux Compatibility Tests
run: |
# Make scripts executable
chmod +x scripts/test-linux-native.sh
chmod +x scripts/test-core.sh
# Run the native Linux compatibility tests (no Docker overhead)
./scripts/test-linux-native.sh
- name: Upload test results on failure
if: failure()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: linux-compatibility-test-failure
path: |
/tmp/xcodeproj-linux-test-*
retention-days: 7
- name: Comment on failure
if: failure()
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ Linux compatibility tests failed after npm publish. Please check the logs and artifacts for details.'
})