From f22e0ef4480388510bc9b0c04fd391c295a1998a Mon Sep 17 00:00:00 2001 From: Cal Stephens Date: Mon, 10 Jun 2024 21:54:36 -0700 Subject: [PATCH] Add CI job to upload artifact to release (#1721) --- .github/workflows/release.yml | 58 ++++++++++++++++++++++++++++++++++ Scripts/spm-artifact-bundle.sh | 17 ++++++++-- 2 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..d567b503c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +on: + release: + types: [created] +name: Build Release Artifacts +jobs: + macos: + name: Build macOS binary + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Build macOS binary + run: swift build -c release --arch arm64 --arch x86 + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: swiftformat_macos + path: .build/apple/Products/Release/swiftformat + retention-days: 5 + + linux: + name: Build SwiftFormat for Linux + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Build it + run: | + swift build --configuration release --static-swift-stdlib --enable-dead-strip + SWIFTFORMAT_BIN_PATH=`swift build --configuration release --show-bin-path` + mv $SWIFTFORMAT_BIN_PATH/swiftformat "${HOME}/swiftformat_linux" + - name: 'Upload Artifact' + uses: actions/upload-artifact@v4 + with: + name: swiftformat_linux + path: ~/swiftformat_linux + retention-days: 5 + + upload: + name: Upload release artifactsts + runs-on: ubuntu-latest + needs: [macos, linux] + steps: + - name: Checkout the repository + uses: actions/checkout@v3 + - uses: actions/download-artifact@v4 + with: + path: downloaded_artifacts + - name: Display structure of downloaded files + run: ls -R downloaded_artifacts + - name: Build artifact bundle + run: ./Scripts/spm-artifact-bundle.sh ${{ github.event.release.name }} downloaded_artifacts/swiftformat_macos/swiftformat downloaded_artifacts/swiftformat_linux/swiftformat_linux + - name: Upload artifact bundle + uses: skx/github-action-publish-binaries@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: 'swiftformat.artifactbundle.zip' \ No newline at end of file diff --git a/Scripts/spm-artifact-bundle.sh b/Scripts/spm-artifact-bundle.sh index 76a919bc2..5896e3f33 100755 --- a/Scripts/spm-artifact-bundle.sh +++ b/Scripts/spm-artifact-bundle.sh @@ -2,12 +2,21 @@ set -e +# By default, parses the current version from `Sources/SwiftFormat.swift`. +# Can be overridden by passing in custom version number as argument, e.g. +# `./Scripts/spm-artifact-bundle.sh VERSION_NUMBER`. +VERSION=${1:-$(./Scripts/get-version.sh)} +MAC_EXECUTABLE=${2:-CommandLineTool/swiftformat} +LINUX_EXECUTABLE=${3:-CommandLineTool/swiftformat_linux} + ARTIFACT_BUNDLE=swiftformat.artifactbundle INFO_TEMPLATE=Scripts/spm-artifact-bundle-info.template -VERSION=$(./Scripts/get-version.sh) MAC_BINARY_OUTPUT_DIR=$ARTIFACT_BUNDLE/swiftformat-$VERSION-macos/bin LINUX_BINARY_OUTPUT_DIR=$ARTIFACT_BUNDLE/swiftformat-$VERSION-linux-gnu/bin +rm -rf swiftformat.artifactbundle +rm -rf swiftformat.artifactbundle.zip + mkdir $ARTIFACT_BUNDLE # Copy license into bundle @@ -17,12 +26,14 @@ cp LICENSE.md $ARTIFACT_BUNDLE sed 's/__VERSION__/'"${VERSION}"'/g' $INFO_TEMPLATE > "${ARTIFACT_BUNDLE}/info.json" # Copy macOS SwiftFormat binary into bundle +chmod +x $MAC_EXECUTABLE mkdir -p $MAC_BINARY_OUTPUT_DIR -cp CommandLineTool/swiftformat $MAC_BINARY_OUTPUT_DIR +cp $MAC_EXECUTABLE $MAC_BINARY_OUTPUT_DIR # Copy Linux SwiftFormat binary into bundle +chmod +x $LINUX_EXECUTABLE mkdir -p $LINUX_BINARY_OUTPUT_DIR -cp CommandLineTool/swiftformat_linux $LINUX_BINARY_OUTPUT_DIR +cp $LINUX_EXECUTABLE $LINUX_BINARY_OUTPUT_DIR # Create ZIP zip -yr - $ARTIFACT_BUNDLE > "${ARTIFACT_BUNDLE}.zip"