https://github.com/phimage/action-swift-cli-build
Build swift cli tool on macOS or ubuntu
https://github.com/phimage/action-swift-cli-build
Last synced: 7 months ago
JSON representation
Build swift cli tool on macOS or ubuntu
- Host: GitHub
- URL: https://github.com/phimage/action-swift-cli-build
- Owner: phimage
- License: mit
- Created: 2022-11-07T13:19:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-11T23:10:58.000Z (over 3 years ago)
- Last Synced: 2025-01-28T22:18:26.281Z (about 1 year ago)
- Size: 20.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# action-swift-cli-build
Build swift cli tool on macOS or ubuntu, to run it or attach it to release
Example in template [swift-cli-template](https://github.com/phimage/swift-cli-template)
## Build and use
```yaml
jobs:
build:
name: Swift on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: phimage/action-swift-cli-build@v1
with:
swift-version: "5.7"
bin-name: "my-binary-name"
- name: Launch my compile cli tools
run: |
$BINARY --help
```
## Release
To upload to a release when publishing it, use `upload-to-release` and pass the `repo-token`.
```yaml
name: release
on:
release:
types: [published]
jobs:
build:
name: Swift on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: phimage/action-swift-cli-build@v1
with:
swift-version: "5.7"
bin-name: "my-binary-name"
upload-to-release: true
repo-token: ${{ secrets.GITHUB_TOKEN }}
```
### Propose an install bash script
A user then could launch a simple command to install your binary from release assets
```bash
sudo curl -sL https://.github.io//install.sh | bash
```
To do so, first active the [github pages](https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages).
Then create an "install.sh" script in your project and do not forget to edit `binary` and `repository` variable to match your project needs.
```bash
#!/usr/bin/env bash
binary_name="yourbinary"
repository="orga/project"
TMP="${TMPDIR}"
if [ "x$TMP" = "x" ]; then
TMP="/tmp/"
fi
TMP="${TMP}cli.$$"
rm -rf "$TMP" || true
mkdir "$TMP"
if [ $? -ne 0 ]; then
echo "failed to mkdir $TMP" >&2
exit 1
fi
cd $TMP
if [[ "$OSTYPE" == "linux-gnu" ]]; then
. /etc/lsb-release
if [ "$DISTRIB_ID" != "Ubuntu" ]; then
echo "Only ubuntu supported"
exit 1
fi
archiveName=$binary_name-x86_64-static-ubuntu-$DISTRIB_CODENAME.zip
elif [[ "$OSTYPE" == "darwin"* ]]; then # Mac OSX
archiveName=$binary_name.zip
else
echo "Unknown os type $OSTYPE, macOS or ubuntu"
exit 1
fi
archive=$TMP/$archiveName
curl -sL https://github.com/$repository/releases/latest/download/$archiveName -o $archive
if [[ "$OSTYPE" == "darwin"* ]]; then # Mac OSX
unzip -q $archive -d $TMP/
else
unzip -q $archive -d $TMP/
fi
binary=$TMP/$binary_name
dst="/usr/local/bin"
echo "Install into $dst/$binary_name"
sudo rm -f $dst/$binary_name
sudo cp $binary $dst/
rm -rf "$TMP"
```