From 5caafa3f7b80bd08f8cf97c3af4d484d10780658 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 15:35:46 -0700 Subject: [PATCH 01/14] Create add-release-asset-macos.yml --- .github/workflows/add-release-asset-macos.yml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/add-release-asset-macos.yml diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml new file mode 100644 index 00000000..5f0553fa --- /dev/null +++ b/.github/workflows/add-release-asset-macos.yml @@ -0,0 +1,35 @@ +name: Build and attach on releases + +on: + release: + types: [published] + +jobs: + release: + runs-on: macos-12 + + steps: + + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.event.release.tag_name }} + + # Should output executable to `.build/release/swift-format` + - name: Build + run: swift build --disable-sandbox -c release + + # Zip the executable so it can be given a descriptive name to distinguish the MacOS and Ubuntu builds + - name: Create archive + id: create-plugin-archive + run: | + FILENAME=swift-format.${{ github.event.release.name }}.macos.zip + zip $FILENAME .build/release/swift-format + echo "ARCHIVE_ABSOLUTE_FILEPATH=$(pwd)/$FILENAME" >> $GITHUB_OUTPUT; + + - uses: meeDamian/github-release@2.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + files: ${{ steps.create-plugin-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }} + gzip: false + allow_override: true From 190d3b3e03afe5a39ea58f5ed3c8b6490905cc9d Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 15:27:42 -0700 Subject: [PATCH 02/14] Create add-release-asset-ubuntu.yml --- .../workflows/add-release-asset-ubuntu.yml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/add-release-asset-ubuntu.yml diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml new file mode 100644 index 00000000..9df76e6c --- /dev/null +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -0,0 +1,35 @@ +name: Build and attach on releases + +on: + release: + types: [published] + +jobs: + release: + runs-on: ubuntu-latest + + steps: + + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.event.release.tag_name }} + + # Should output executable to `.build/release/swift-format` + - name: Build + run: swift build --disable-sandbox -c release + + # Zip the executable so it can be given a descriptive name to distinguish the MacOS and Ubuntu builds + - name: Create archive + id: create-plugin-archive + run: | + FILENAME=swift-format.${{ github.event.release.name }}.ubuntu.zip + zip $FILENAME .build/release/swift-format + echo "ARCHIVE_ABSOLUTE_FILEPATH=$(pwd)/$FILENAME" >> $GITHUB_OUTPUT; + + - uses: meeDamian/github-release@2.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + files: ${{ steps.create-plugin-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }} + gzip: false + allow_override: true From 4581d300b04d9ca52463a127146f6e0588b24811 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 15:46:00 -0700 Subject: [PATCH 03/14] Use `softprops/action-gh-release` because `meeDamian/github-release` not working on MacOS --- .github/workflows/add-release-asset-macos.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 5f0553fa..02200e21 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -27,9 +27,7 @@ jobs: zip $FILENAME .build/release/swift-format echo "ARCHIVE_ABSOLUTE_FILEPATH=$(pwd)/$FILENAME" >> $GITHUB_OUTPUT; - - uses: meeDamian/github-release@2.0 + - name: Attach asset + uses: softprops/action-gh-release@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} - files: ${{ steps.create-plugin-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }} - gzip: false - allow_override: true + files: ${{ steps.create-plugin-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }} \ No newline at end of file From 5bbf03e9e9d93b9182bfc175305cd1d20fe81862 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:07:25 -0700 Subject: [PATCH 04/14] Add write permission --- .github/workflows/add-release-asset-macos.yml | 3 +++ .github/workflows/add-release-asset-ubuntu.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 02200e21..67bbb63c 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -8,6 +8,9 @@ jobs: release: runs-on: macos-12 + permissions: + contents: write + steps: - name: Checkout diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index 9df76e6c..a9c789a2 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -8,6 +8,9 @@ jobs: release: runs-on: ubuntu-latest + permissions: + contents: write + steps: - name: Checkout From 4cf4b973393bf00b37f51834c815dd47e70533e2 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:11:49 -0700 Subject: [PATCH 05/14] Update version number --- .github/workflows/add-release-asset-macos.yml | 9 +++++++++ .github/workflows/add-release-asset-ubuntu.yml | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 67bbb63c..08d8ca50 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -18,6 +18,15 @@ jobs: with: ref: ${{ github.event.release.tag_name }} + # @see https://github.com/apple/swift-format/commit/fbfe1869527923dd9f9b2edac148baccfce0dce7 + # NB: sed syntax differs between MacOS and Ubuntu + - name: Edit `VersionOptions.swift` to update the version number + env: + CURRENT_RELEASE: ${{ github.event.release.tag_name }} + run: | + find . -name 'VersionOptions.swift' -exec sed -i '' 's/print("[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}")/print("'$CURRENT_RELEASE'")/g' {} + + cat Sources/swift-format/VersionOptions.swift + # Should output executable to `.build/release/swift-format` - name: Build run: swift build --disable-sandbox -c release diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index a9c789a2..d9ab83a7 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -18,6 +18,15 @@ jobs: with: ref: ${{ github.event.release.tag_name }} + # @see https://github.com/apple/swift-format/commit/fbfe1869527923dd9f9b2edac148baccfce0dce7 + # NB: sed syntax differs between MacOS and Ubuntu + - name: Edit `VersionOptions.swift` to update the version number + env: + CURRENT_RELEASE: ${{ github.event.release.tag_name }} + run: | + find . -name 'VersionOptions.swift' -exec sed -i 's/print("[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}")/print("'$CURRENT_RELEASE'")/g' {} + + cat Sources/swift-format/VersionOptions.swift + # Should output executable to `.build/release/swift-format` - name: Build run: swift build --disable-sandbox -c release From 6972d60dafbec679736db7fdfc5dd4f0a6d56ffc Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:29:47 -0700 Subject: [PATCH 06/14] Do not restrict version names to semver because past tags have varied --- .github/workflows/add-release-asset-macos.yml | 2 +- .github/workflows/add-release-asset-ubuntu.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 08d8ca50..0b1e5c25 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -24,7 +24,7 @@ jobs: env: CURRENT_RELEASE: ${{ github.event.release.tag_name }} run: | - find . -name 'VersionOptions.swift' -exec sed -i '' 's/print("[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}")/print("'$CURRENT_RELEASE'")/g' {} + + find . -name 'VersionOptions.swift' -exec sed -i '' 's/print(".*")/print("'$CURRENT_RELEASE'")/g' {} + cat Sources/swift-format/VersionOptions.swift # Should output executable to `.build/release/swift-format` diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index d9ab83a7..20a7f8d4 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -24,7 +24,7 @@ jobs: env: CURRENT_RELEASE: ${{ github.event.release.tag_name }} run: | - find . -name 'VersionOptions.swift' -exec sed -i 's/print("[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}")/print("'$CURRENT_RELEASE'")/g' {} + + find . -name 'VersionOptions.swift' -exec sed -i 's/print(".*")/print("'$CURRENT_RELEASE'")/g' {} + cat Sources/swift-format/VersionOptions.swift # Should output executable to `.build/release/swift-format` From 9dc70406b8123a5c35ef04d123cb33d2c227b658 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:30:23 -0700 Subject: [PATCH 07/14] Move to build directory before zipping Otherwise the directory structure was zipped too --- .github/workflows/add-release-asset-macos.yml | 3 ++- .github/workflows/add-release-asset-ubuntu.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 0b1e5c25..03fb09e4 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -36,7 +36,8 @@ jobs: id: create-plugin-archive run: | FILENAME=swift-format.${{ github.event.release.name }}.macos.zip - zip $FILENAME .build/release/swift-format + cd .build/release/ + zip $FILENAME *.* echo "ARCHIVE_ABSOLUTE_FILEPATH=$(pwd)/$FILENAME" >> $GITHUB_OUTPUT; - name: Attach asset diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index 20a7f8d4..ed64b5fb 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -36,7 +36,8 @@ jobs: id: create-plugin-archive run: | FILENAME=swift-format.${{ github.event.release.name }}.ubuntu.zip - zip $FILENAME .build/release/swift-format + cd .build/release/ + zip $FILENAME swift-format echo "ARCHIVE_ABSOLUTE_FILEPATH=$(pwd)/$FILENAME" >> $GITHUB_OUTPUT; - uses: meeDamian/github-release@2.0 From b1f8385ce4ac75defd264d9738084b8f891c75fa Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:30:40 -0700 Subject: [PATCH 08/14] Add codesign command to enable running un-notarized app --- .github/workflows/add-release-asset-macos.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 03fb09e4..833250f7 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -37,6 +37,7 @@ jobs: run: | FILENAME=swift-format.${{ github.event.release.name }}.macos.zip cd .build/release/ + echo "xattr -c swift-format" > disable-codesigning.sh zip $FILENAME *.* echo "ARCHIVE_ABSOLUTE_FILEPATH=$(pwd)/$FILENAME" >> $GITHUB_OUTPUT; From bb671ef3c7a614d5feccf6d5df1b1ad93e7cc098 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:33:30 -0700 Subject: [PATCH 09/14] Use same attach asset Action in both MacOS and Ubuntu workflows The other was only working for Ubuntu. --- .github/workflows/add-release-asset-ubuntu.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index ed64b5fb..eb488390 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -40,9 +40,7 @@ jobs: zip $FILENAME swift-format echo "ARCHIVE_ABSOLUTE_FILEPATH=$(pwd)/$FILENAME" >> $GITHUB_OUTPUT; - - uses: meeDamian/github-release@2.0 + - name: Attach asset + uses: softprops/action-gh-release@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} files: ${{ steps.create-plugin-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }} - gzip: false - allow_override: true From 3e93b5033cd5853bb4fbd064e98855f5d39cd009 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:41:14 -0700 Subject: [PATCH 10/14] Update link to version number commit --- .github/workflows/add-release-asset-macos.yml | 2 +- .github/workflows/add-release-asset-ubuntu.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 833250f7..c35e629d 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -18,7 +18,7 @@ jobs: with: ref: ${{ github.event.release.tag_name }} - # @see https://github.com/apple/swift-format/commit/fbfe1869527923dd9f9b2edac148baccfce0dce7 + # @see https://github.com/apple/swift-format/commit/705038361379825ef201d96f2709587b08212f5a # NB: sed syntax differs between MacOS and Ubuntu - name: Edit `VersionOptions.swift` to update the version number env: diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index eb488390..5216716c 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -18,7 +18,7 @@ jobs: with: ref: ${{ github.event.release.tag_name }} - # @see https://github.com/apple/swift-format/commit/fbfe1869527923dd9f9b2edac148baccfce0dce7 + # @see https://github.com/apple/swift-format/commit/705038361379825ef201d96f2709587b08212f5a # NB: sed syntax differs between MacOS and Ubuntu - name: Edit `VersionOptions.swift` to update the version number env: From 417171209da6010f95005e9616748880f40fd76b Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:43:58 -0700 Subject: [PATCH 11/14] Fix: be specific with what is added to the zip file --- .github/workflows/add-release-asset-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index c35e629d..03eed143 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -38,7 +38,7 @@ jobs: FILENAME=swift-format.${{ github.event.release.name }}.macos.zip cd .build/release/ echo "xattr -c swift-format" > disable-codesigning.sh - zip $FILENAME *.* + zip $FILENAME swift-format disable-codesigning.sh echo "ARCHIVE_ABSOLUTE_FILEPATH=$(pwd)/$FILENAME" >> $GITHUB_OUTPUT; - name: Attach asset From adb1d0f9c83d80ef893267cb862710c77c4eb3ee Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:47:40 -0700 Subject: [PATCH 12/14] Run the executable after build to ensure it is working! --- .github/workflows/add-release-asset-macos.yml | 4 ++++ .github/workflows/add-release-asset-ubuntu.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 03eed143..89dc05db 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -31,6 +31,10 @@ jobs: - name: Build run: swift build --disable-sandbox -c release + # Smoke test + - name: Test the executable works + run: .build/release/swift-format --version + # Zip the executable so it can be given a descriptive name to distinguish the MacOS and Ubuntu builds - name: Create archive id: create-plugin-archive diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index 5216716c..00466ad0 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -31,6 +31,10 @@ jobs: - name: Build run: swift build --disable-sandbox -c release + # Smoke test + - name: Test the executable works + run: .build/release/swift-format --version + # Zip the executable so it can be given a descriptive name to distinguish the MacOS and Ubuntu builds - name: Create archive id: create-plugin-archive From 9d73dc3fc55edde4f67742585b21036eebd5dc80 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 16:59:13 -0700 Subject: [PATCH 13/14] Add platform to workflow names --- .github/workflows/add-release-asset-macos.yml | 2 +- .github/workflows/add-release-asset-ubuntu.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 89dc05db..5ed0543a 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -1,4 +1,4 @@ -name: Build and attach on releases +name: Build and attach on releases – MacOS on: release: diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index 00466ad0..d8f1aeb1 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -1,4 +1,4 @@ -name: Build and attach on releases +name: Build and attach on releases - Ubuntu on: release: From cb3df73579cced1fbb5c4337467960dce7f3c948 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Tue, 5 Sep 2023 17:22:32 -0700 Subject: [PATCH 14/14] Rename `id` to remove "plugin" This was copied from a WordPress plugin! --- .github/workflows/add-release-asset-macos.yml | 4 ++-- .github/workflows/add-release-asset-ubuntu.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/add-release-asset-macos.yml b/.github/workflows/add-release-asset-macos.yml index 5ed0543a..c9fed3c4 100644 --- a/.github/workflows/add-release-asset-macos.yml +++ b/.github/workflows/add-release-asset-macos.yml @@ -37,7 +37,7 @@ jobs: # Zip the executable so it can be given a descriptive name to distinguish the MacOS and Ubuntu builds - name: Create archive - id: create-plugin-archive + id: create-archive run: | FILENAME=swift-format.${{ github.event.release.name }}.macos.zip cd .build/release/ @@ -48,4 +48,4 @@ jobs: - name: Attach asset uses: softprops/action-gh-release@v1 with: - files: ${{ steps.create-plugin-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }} \ No newline at end of file + files: ${{ steps.create-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }} \ No newline at end of file diff --git a/.github/workflows/add-release-asset-ubuntu.yml b/.github/workflows/add-release-asset-ubuntu.yml index d8f1aeb1..d62644b3 100644 --- a/.github/workflows/add-release-asset-ubuntu.yml +++ b/.github/workflows/add-release-asset-ubuntu.yml @@ -37,7 +37,7 @@ jobs: # Zip the executable so it can be given a descriptive name to distinguish the MacOS and Ubuntu builds - name: Create archive - id: create-plugin-archive + id: create-archive run: | FILENAME=swift-format.${{ github.event.release.name }}.ubuntu.zip cd .build/release/ @@ -47,4 +47,4 @@ jobs: - name: Attach asset uses: softprops/action-gh-release@v1 with: - files: ${{ steps.create-plugin-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }} + files: ${{ steps.create-archive.outputs.ARCHIVE_ABSOLUTE_FILEPATH }}