|
1 | | -# This workflow will build a Swift project |
2 | | -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift |
3 | | - |
4 | | -name: Swift |
| 1 | +name: Build & Release |
5 | 2 |
|
6 | 3 | on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Release version (e.g. 1.0.0)" |
| 8 | + required: true |
| 9 | + default: "1.0.0" |
7 | 10 | push: |
8 | | - branches: [ "main" ] |
9 | | - pull_request: |
10 | | - branches: [ "main" ] |
| 11 | + tags: |
| 12 | + - "v*" |
11 | 13 |
|
12 | 14 | jobs: |
13 | 15 | build: |
| 16 | + runs-on: macos-15 |
14 | 17 |
|
15 | | - runs-on: macos-latest |
| 18 | + permissions: |
| 19 | + contents: write |
16 | 20 |
|
17 | 21 | steps: |
18 | | - - uses: actions/checkout@v4 |
19 | | - - name: Build |
20 | | - run: swift build -v |
21 | | - - name: Run tests |
22 | | - run: swift test -v |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Set version from tag or input |
| 25 | + run: | |
| 26 | + if [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 27 | + VERSION="${GITHUB_REF_NAME#v}" |
| 28 | + else |
| 29 | + VERSION="${{ github.event.inputs.version }}" |
| 30 | + fi |
| 31 | + echo "VERSION=$VERSION" >> "$GITHUB_ENV" |
| 32 | +
|
| 33 | + - name: Build release binary |
| 34 | + run: swift build -c release |
| 35 | + |
| 36 | + - name: Create app bundle |
| 37 | + run: | |
| 38 | + APP_NAME="Dispres" |
| 39 | + BUNDLE_DIR="$APP_NAME.app" |
| 40 | + CONTENTS="$BUNDLE_DIR/Contents" |
| 41 | + MACOS="$CONTENTS/MacOS" |
| 42 | + RESOURCES="$CONTENTS/Resources" |
| 43 | +
|
| 44 | + mkdir -p "$MACOS" "$RESOURCES" |
| 45 | + cp ".build/release/$APP_NAME" "$MACOS/$APP_NAME" |
| 46 | + cp "Sources/Dispres/Resources/Info.plist" "$CONTENTS/Info.plist" |
| 47 | +
|
| 48 | + # Stamp version into Info.plist |
| 49 | + /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $VERSION" "$CONTENTS/Info.plist" |
| 50 | + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $VERSION" "$CONTENTS/Info.plist" |
| 51 | +
|
| 52 | + if [ -f "AppIcon.icns" ]; then |
| 53 | + cp "AppIcon.icns" "$RESOURCES/AppIcon.icns" |
| 54 | + fi |
| 55 | +
|
| 56 | + codesign --force --sign - "$BUNDLE_DIR" |
| 57 | +
|
| 58 | + - name: Create DMG |
| 59 | + run: | |
| 60 | + hdiutil create -volname "Dispres" \ |
| 61 | + -srcfolder Dispres.app \ |
| 62 | + -ov -format UDZO \ |
| 63 | + "Dispres-$VERSION-macOS.dmg" |
| 64 | +
|
| 65 | + - name: Create ZIP |
| 66 | + run: | |
| 67 | + ditto -c -k --sequesterRsrc --keepParent Dispres.app "Dispres-$VERSION-macOS.zip" |
| 68 | +
|
| 69 | + - name: Create GitHub Release |
| 70 | + uses: softprops/action-gh-release@v2 |
| 71 | + with: |
| 72 | + tag_name: ${{ github.ref_type == 'tag' && github.ref_name || format('v{0}', env.VERSION) }} |
| 73 | + name: Dispres v${{ env.VERSION }} |
| 74 | + draft: false |
| 75 | + generate_release_notes: true |
| 76 | + files: | |
| 77 | + Dispres-${{ env.VERSION }}-macOS.dmg |
| 78 | + Dispres-${{ env.VERSION }}-macOS.zip |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments