-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
487d550
commit a983d75
Showing
1 changed file
with
60 additions
and
81 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,86 @@ | ||
name: release | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
type: choice | ||
required: true | ||
description: 'Version number to bump' | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
|
||
permissions: | ||
contents: write | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
create-release: | ||
name: Create Release | ||
publish-dry-run: | ||
name: "Runs cargo publish --dry-run" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v2 | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Create Release Notes | ||
uses: actions/github-script@v5 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
await github.request(`POST /repos/${{ github.repository }}/releases`, { | ||
tag_name: "${{ github.ref }}", | ||
generate_release_notes: true | ||
}); | ||
build-artifacts: | ||
name: 'Build artifacts for ${{ matrix.os }}' | ||
runs-on: ${{ matrix.os }} | ||
needs: create-release | ||
strategy: | ||
matrix: | ||
name: | ||
- linux | ||
- macos | ||
- windows | ||
include: | ||
- name: linux | ||
os: ubuntu-latest | ||
artifact_name: 'http-server-linux' | ||
asset_name: 'http-server' | ||
asset_extension: '.tar.gz' | ||
profile: minimal | ||
toolchain: stable | ||
|
||
- name: macos | ||
os: macos-latest | ||
artifact_name: 'http-server-macos' | ||
asset_name: 'http-server' | ||
asset_extension: '.tar.gz' | ||
- name: publish crate | ||
run: cargo publish --dry-run | ||
|
||
- name: windows | ||
os: windows-latest | ||
artifact_name: 'http-server-windows.exe' | ||
asset_name: 'http-server.exe' | ||
asset_extension: '.zip' | ||
release: | ||
name: Create Release | ||
needs: publish-dry-run | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout source code | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup environment variables | ||
shell: bash | ||
run: | | ||
RELEASE_VERSION=$(echo ${GITHUB_REF:10}) >> $GITHUB_ENV | ||
- name: Setup Rust Toolchain | ||
- name: Setup Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
|
||
- name: Build optimized executable | ||
run: cargo build --release --locked | ||
- name: Install `cargo-edit` | ||
run: cargo install cargo-edit | ||
|
||
- id: cargo-set-version | ||
name: Set Version | ||
run: cargo set-version --bump ${{ inputs.version }} | ||
|
||
- name: Archive release assets | ||
shell: bash | ||
- name: Set Crate Version as Environment Variable | ||
run: | | ||
if [ "${{ matrix.os }}" = "windows-latest" ]; then | ||
cp target/release/http-server.exe ${{ matrix.asset_name }} | ||
else | ||
cp target/release/http-server "${{ matrix.asset_name }}" | ||
fi | ||
- name: Attach builded binaries to release | ||
uses: svenstaro/upload-release-action@v1-release | ||
with: | ||
asset_name: 'http-server_${{ matrix.os }}' | ||
file: '${{ matrix.asset_name }}' | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
tag: ${{ github.ref }} | ||
|
||
publish-crate: | ||
name: Publish to crates.io | ||
runs-on: ubuntu-latest | ||
needs: build-artifacts | ||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v2 | ||
CARGO_TOML_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/[\"]/, "", $2); printf("%s",$2) }' Cargo.toml) | ||
echo "CRATE_VERSION=$CARGO_TOML_VERSION" >> $GITHUB_ENV | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
- name: Create Commit | ||
run: | | ||
git config --global user.name 'github-actions[bot]' | ||
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
git add . | ||
git commit -m "chore: bump version to v$CRATE_VERSION" | ||
git push origin main --follow-tags | ||
- run: cargo login ${CRATES_IO_TOKEN} | ||
- name: Login to Crates.io | ||
run: cargo login ${CRATES_IO_TOKEN} | ||
env: | ||
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} | ||
|
||
- name: publish crate | ||
- name: Publish crate | ||
run: cargo publish | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
await github.request(`POST /repos/${{ github.repository }}/releases`, { | ||
tag_name: "v${{ env.CRATE_VERSION }}", | ||
generate_release_notes: true | ||
}); |