Release Build #6
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 Build | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version number (e.g. 0.1.0)' | |
required: true | |
jobs: | |
get_build_number: | |
runs-on: ubuntu-22.04 | |
outputs: | |
build_number: ${{ steps.set_number.outputs.build_number }} | |
steps: | |
- name: Generate build number | |
id: set_number | |
run: | | |
echo "build_number=$(( $GITHUB_RUN_NUMBER ))" >> $GITHUB_OUTPUT | |
build-x86_64: | |
needs: get_build_number | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Change Cargo.toml version | |
run: | | |
VERSION="${{ github.event.inputs.version }}-build${{ needs.get_build_number.outputs.build_number }}" | |
sed -i "s/^version[ ]*=[ ]*\"[^\"]*\"/version = \"${VERSION}\"/" Cargo.toml | |
echo "Updated version in Cargo.toml:" | |
grep "^version" Cargo.toml | |
- name: Build | |
run: cargo build --release --target x86_64-unknown-linux-gnu | |
- name: Strip binary | |
run: strip target/x86_64-unknown-linux-gnu/release/komandan | |
- name: Create Release Tag | |
run: | | |
TAG="v${{ github.event.inputs.version }}-build${{ needs.get_build_number.outputs.build_number }}" | |
echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV | |
- name: Zip artifact | |
run: zip -j komandan_${{ env.RELEASE_TAG }}-linux-x86_64.zip target/x86_64-unknown-linux-gnu/release/komandan | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-x86_64-artifact | |
path: | | |
komandan_${{ env.RELEASE_TAG }}-linux-x86_64.zip | |
build-aarch64: | |
needs: get_build_number | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Change Cargo.toml version | |
run: | | |
VERSION="${{ github.event.inputs.version }}-build${{ needs.get_build_number.outputs.build_number }}" | |
sed -i "s/^version[ ]*=[ ]*\"[^\"]*\"/version = \"${VERSION}\"/" Cargo.toml | |
echo "Updated version in Cargo.toml:" | |
grep "^version" Cargo.toml | |
- name: Add target aarch64-unknown-linux-gnu | |
run: rustup target add aarch64-unknown-linux-gnu | |
- name: Install aarch64-linux-gnu-gcc | |
run: sudo apt update && sudo apt install -y gcc-aarch64-linux-gnu | |
- name: Build | |
run: cargo build --release --target aarch64-unknown-linux-gnu | |
- name: Strip binary | |
run: aarch64-linux-gnu-strip target/aarch64-unknown-linux-gnu/release/komandan | |
- name: Create Release Tag | |
run: | | |
TAG="v${{ github.event.inputs.version }}-build${{ needs.get_build_number.outputs.build_number }}" | |
echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV | |
- name: Zip artifact | |
run: zip -j komandan_${{ env.RELEASE_TAG }}-linux-aarch64.zip target/aarch64-unknown-linux-gnu/release/komandan | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-aarch64-artifact | |
path: | | |
komandan_${{ env.RELEASE_TAG }}-linux-aarch64.zip | |
release: | |
runs-on: ubuntu-22.04 | |
needs: [get_build_number, build-x86_64, build-aarch64] | |
permissions: | |
contents: write | |
steps: | |
- name: Download artifact x86_64 | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-x86_64-artifact | |
- name: Download artifact aarch64 | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-aarch64-artifact | |
- name: Create Release Tag | |
run: | | |
TAG="v${{ github.event.inputs.version }}-build${{ needs.get_build_number.outputs.build_number }}" | |
echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV | |
- name: Create GitHub Release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ env.RELEASE_TAG }} | |
name: ${{ env.RELEASE_TAG }} | |
body: Release ${{ env.RELEASE_TAG }} | |
artifacts: | | |
komandan_${{ env.RELEASE_TAG }}-linux-x86_64.zip | |
komandan_${{ env.RELEASE_TAG }}-linux-aarch64.zip | |
docker-build-and-push: | |
runs-on: ubuntu-22.04 | |
needs: [get_build_number, release] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get version | |
run: | | |
VERSION="${{ github.event.inputs.version }}-build${{ needs.get_build_number.outputs.build_number }}" | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
- name: Change Cargo.toml version | |
run: | | |
sed -i "s/^version[ ]*=[ ]*\"[^\"]*\"/version = \"${{ env.VERSION }}\"/" Cargo.toml | |
echo "Updated version in Cargo.toml:" | |
grep "^version" Cargo.toml | |
- name: Build Docker image | |
run: docker build -t hahnavi/komandan:${{ env.VERSION }} . | |
- name: Retag image | |
run: docker tag hahnavi/komandan:${{ env.VERSION }} hahnavi/komandan:latest | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Push Docker images | |
run: | | |
docker push hahnavi/komandan:${{ env.VERSION }} | |
docker push hahnavi/komandan:latest |