Skip to content

Add ci and cd

Add ci and cd #1

Workflow file for this run

name: Release & Publish
on:
push:
tags:
- "**"
jobs:
release:
name: Create release
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.release-tag.outputs.tag }}
id: ${{ steps.release-id.outputs.id }}
steps:
- name: Determine tag
id: release-tag
run: |
RELEASE_TAG=${GITHUB_REF#refs/tags/}
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
echo "tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT
- name: Create the release
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases \
--data '{
"tag_name": "${{ env.RELEASE_TAG }}",
"name": "Release ${{ env.RELEASE_TAG }}",
"generate_release_notes": true
}' \
-o release.json
- name: Determine release id
id: release-id
run: |
RELEASE_ID=$(jq -r '.id' release.json)
echo "id=${RELEASE_ID}" >> $GITHUB_OUTPUT
build-and-publish:
name: Build and publish
runs-on: ${{ matrix.job.os }}
strategy:
matrix:
job:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
needs: release
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build binary
run: |
rustup update stable
rustup default stable
rustup target add ${{ matrix.job.target }}
cargo build --release --target ${{ matrix.job.target }}
- name: Create tarball
run: |
TARBALL=sws-${{ needs.release.outputs.tag }}-${{ matrix.job.target }}.tar.gz
tar -zcvf ${TARBALL} -C target/${{ matrix.job.target }}/release sws
echo "TARBALL=${TARBALL}" >> $GITHUB_ENV
- name: Upload tarball to the release
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H 'Content-Type: application/octet-stream' \
--upload-file ${{ env.TARBALL }} \
https://uploads.github.com/repos/${{ github.repository }}/releases/${{ needs.release.outputs.id }}/assets?name=${{ env.TARBALL }}