GH workflow for creating a new release #1
Workflow file for this run
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 | |
on: | |
push: | |
tags: | |
- "v[0-9]+.[0-9]+.[0-9]+" | |
jobs: | |
create-release: | |
runs-on: ubuntu-latest | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
version: ${{ steps.get_version.outputs.version }} | |
steps: | |
- name: Get version from tag | |
id: get_version | |
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref_name }} | |
draft: false | |
prerelease: false | |
build-release: | |
needs: create-release | |
strategy: | |
matrix: | |
include: | |
- os: ubuntu-20.04 | |
target: x86_64-unknown-linux-gnu | |
binary_name: decent-cloud | |
asset_name: decent-cloud-linux-amd64 | |
- os: macos-latest | |
target: x86_64-apple-darwin | |
binary_name: decent-cloud | |
asset_name: decent-cloud-darwin-amd64 | |
- os: ubuntu-20.04 | |
target: x86_64-pc-windows-gnu | |
binary_name: decent-cloud.exe | |
asset_name: decent-cloud-windows-amd64.exe | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ matrix.target }} | |
- name: Install cross-compilation tools | |
if: matrix.target == 'x86_64-pc-windows-gnu' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y mingw-w64 | |
- name: Build Release Binary | |
run: | | |
if [ "${{ matrix.target }}" = "x86_64-pc-windows-gnu" ]; then | |
cargo install cross --git https://github.com/cross-rs/cross | |
cross build --release --target ${{ matrix.target }} -p cli | |
else | |
cargo build --release --target ${{ matrix.target }} -p cli | |
fi | |
- name: Prepare binary | |
run: | | |
if [ "${{ matrix.target }}" = "x86_64-pc-windows-gnu" ]; then | |
cp target/${{ matrix.target }}/release/${{ matrix.binary_name }} ${{ matrix.asset_name }} | |
else | |
cp target/${{ matrix.target }}/release/${{ matrix.binary_name }} ${{ matrix.asset_name }} | |
fi | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create-release.outputs.upload_url }} | |
asset_path: ./${{ matrix.asset_name }} | |
asset_name: ${{ matrix.asset_name }} | |
asset_content_type: application/octet-stream | |
update-version: | |
needs: [create-release, build-release] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update version in Cargo.toml files | |
run: | | |
VERSION="${{ needs.create-release.outputs.version }}" | |
for toml in $(find . -name "Cargo.toml"); do | |
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" "$toml" | |
done | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "chore: bump version to ${{ needs.create-release.outputs.version }}" | |
title: "chore: bump version to ${{ needs.create-release.outputs.version }}" | |
body: | | |
Updates version in Cargo.toml files to match the latest release. | |
This PR was automatically created by the release workflow. | |
branch: bump-version-${{ needs.create-release.outputs.version }} | |
base: main |