Merge pull request #33 from jkfran/dependabot/cargo/mio-0.8.11 #55
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: Release | |
permissions: | |
contents: write | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
check_release: | |
runs-on: ubuntu-latest | |
outputs: | |
releaseExists: ${{ steps.check_release.outputs.releaseExists }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Check if release exists | |
id: check_release | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const { owner, repo } = context.repo; | |
const fs = require("fs"); | |
const content = fs.readFileSync("Cargo.toml", "utf8"); | |
const match = content.match(/^version = "(.*?)"/m); | |
const version = match ? match[1] : ""; | |
const tag = `v${version}`; | |
console.log("Extracted version: ", tag); | |
let releaseExists = false; | |
try { | |
await github.rest.repos.getReleaseByTag({ | |
owner, | |
repo, | |
tag, | |
}); | |
releaseExists = true; | |
} catch (error) { | |
if (error.status !== 404) { | |
throw error; | |
} | |
} | |
console.log("Release exists: ", releaseExists); | |
core.setOutput("releaseExists", releaseExists); | |
return { releaseExists }; | |
release: | |
needs: check_release | |
if: ${{ needs.check_release.outputs.releaseExists == 'false' }} | |
strategy: | |
matrix: | |
target: | |
- x86_64-unknown-linux-gnu | |
- i686-unknown-linux-gnu | |
- aarch64-unknown-linux-gnu | |
- armv7-unknown-linux-gnueabihf | |
- arm-unknown-linux-gnueabihf | |
- powerpc64le-unknown-linux-gnu | |
- s390x-unknown-linux-gnu | |
- aarch64-apple-darwin | |
- x86_64-apple-darwin | |
- x86_64-pc-windows-gnu | |
runs-on: ${{ (matrix.target == 'aarch64-apple-darwin' || matrix.target == 'x86_64-apple-darwin') && 'macos-latest' || 'ubuntu-latest' }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
target: ${{ matrix.target }} | |
override: true | |
- name: Install mingw-w64 | |
run: sudo apt install -y mingw-w64 | |
if: matrix.target == 'x86_64-pc-windows-gnu' | |
- name: Build target | |
uses: actions-rs/cargo@v1 | |
with: | |
use-cross: true | |
command: build | |
args: --release --target ${{ matrix.target }} | |
- name: Package binaries | |
shell: bash | |
run: | | |
cd target/${{ matrix.target }}/release | |
short_target=$(echo "${{ matrix.target }}" | sed 's/-unknown//') | |
if [[ $short_target == *"windows"* ]]; then | |
tar czvf ../../../killport-${short_target}.tar.gz killport.exe | |
else | |
tar czvf ../../../killport-${short_target}.tar.gz killport | |
fi | |
cd - | |
- name: Extract version from Cargo.toml | |
id: get_version | |
run: | | |
VERSION=$(grep '^version =' Cargo.toml | head -n 1 | awk '{print $3}' | tr -d '"' | tr -d "\n") | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "Found version: $VERSION" | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Create release and upload assets | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: v${{ env.VERSION }} | |
name: Release v${{ env.VERSION }} | |
files: 'killport*' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
publish: | |
needs: release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
- name: Publish to crates.io | |
run: cargo publish --token ${{ secrets.CRATES_IO }} |