Build Release Artifacts #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Release Artifacts | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: 'Ref to build (branch, tag or SHA)' | |
required: false | |
default: 'main' | |
jobs: | |
macos: | |
name: Build macOS binary | |
runs-on: macos-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set Version Number | |
run: echo "Using version number $GITHUB_REF_NAME" && sed -i '' "s/let swiftFormatVersion = \"[^\"]*\"/let swiftFormatVersion = \"$GITHUB_REF_NAME\"/" Sources/SwiftFormat.swift | |
- name: Build macOS binary | |
run: swift build -c release --arch arm64 --arch x86_64 | |
- 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@v4 | |
- name: Set Version Number | |
run: echo "Using version number $GITHUB_REF_NAME" && sed -i "s/let swiftFormatVersion = \"[^\"]*\"/let swiftFormatVersion = \"$GITHUB_REF_NAME\"/" Sources/SwiftFormat.swift | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Install cross-binutils for aarch64 | |
run: sudo apt install -y binutils-aarch64-linux-gnu | |
- name: Build and export binaries | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
target: builder | |
outputs: type=local,dest=artifacts | |
- name: Strip and Move binaries | |
run: | | |
strip artifacts/linux_amd64/workspace/swiftformat | |
mv artifacts/linux_amd64/workspace/swiftformat "${HOME}/swiftformat_linux" | |
aarch64-linux-gnu-strip artifacts/linux_arm64/workspace/swiftformat | |
mv artifacts/linux_arm64/workspace/swiftformat "${HOME}/swiftformat_linux_aarch64" | |
- name: Upload AMD64 Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: swiftformat_linux | |
path: ~/swiftformat_linux | |
retention-days: 5 | |
- name: Upload ARM64 Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: swiftformat_linux_aarch64 | |
path: ~/swiftformat_linux_aarch64 | |
retention-days: 5 | |
upload: | |
name: Upload release artifacts | |
runs-on: ubuntu-latest | |
needs: [macos, linux] | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
- 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 downloaded_artifacts/swiftformat_macos/swiftformat downloaded_artifacts/swiftformat_linux/swiftformat_linux downloaded_artifacts/swiftformat_linux_aarch64/swiftformat_linux_aarch64 | |
- name: Upload artifact bundle | |
uses: skx/github-action-publish-binaries@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
args: 'swiftformat.artifactbundle.zip' |