From 7e96b475c92cfa2cb321af222de94eb0157532e0 Mon Sep 17 00:00:00 2001 From: Vova Lando Date: Mon, 25 Nov 2024 18:48:03 +0200 Subject: [PATCH] feat: releases --- .github/workflows/release.yml | 83 ++++++++++++++++++++++++++ .github/workflows/rust-cargo-build.yml | 48 --------------- Dockerfile | 5 -- 3 files changed, 83 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/rust-cargo-build.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8ad9553 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,83 @@ +name: Build and Release + +on: + push: + tags: + - 'v*' + +jobs: + build-and-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: Build release binary + run: | + cargo build --release + mkdir -p dist + cp target/release/kalatori dist/ + + - name: Extract changelog section + run: | + VERSION=${{ github.ref_name }} + CLEAN_VERSION=$(echo $VERSION | sed 's/^v//') + + sed -n "/^## \\[$CLEAN_VERSION\\]/,/^## \\[/p" CHANGELOG.md | sed '$d' > dist/CHANGELOG_${VERSION}.md + echo "### 📦 Docker Image: " >> dist/CHANGELOG_${VERSION}.md + echo "Docker Image: \`docker pull ${{ secrets.DOCKER_USERNAME }}/kalatori:${CLEAN_VERSION}\`" >> dist/CHANGELOG_${VERSION}.md + + echo "Extracted changelog:" + cat dist/CHANGELOG_${VERSION}.md + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: kalatori-${{ github.ref_name }} + path: dist/ + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build and push Docker image + run: | + IMAGE_NAME="${{ secrets.DOCKER_USERNAME }}/kalatori" + TAG="${{ github.ref_name }}" + CLEAN_TAG=$(echo $TAG | sed 's/^v//') + + docker build -t $IMAGE_NAME:$CLEAN_TAG . + docker tag $IMAGE_NAME:$CLEAN_TAG $IMAGE_NAME:latest + + docker push $IMAGE_NAME:$CLEAN_TAG + docker push $IMAGE_NAME:latest + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref_name }} + release_name: ${{ github.ref_name }} + body_path: dist/CHANGELOG_${{ github.ref_name }}.md + draft: false + prerelease: false + + - name: Upload release assets + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/kalatori + asset_name: kalatori-${{ github.ref_name }}-linux-x86_64 + asset_content_type: application/octet-stream diff --git a/.github/workflows/rust-cargo-build.yml b/.github/workflows/rust-cargo-build.yml deleted file mode 100644 index d1549bf..0000000 --- a/.github/workflows/rust-cargo-build.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Rust cargo build and draft release - -on: - push: - branches: - - main - -jobs: - cargo-build: - name: Cargo build - runs-on: ubuntu-latest - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.12.1 - with: - access_token: ${{ github.token }} - - - name: Checkout sources - uses: actions/checkout@v4.2.2 - with: - fetch-depth: 50 - submodules: 'recursive' - - - name: Install Rust stable toolchain - uses: actions-rs/toolchain@v1.0.7 - with: - profile: minimal - toolchain: stable - override: true - - - name: Rust Cache - uses: Swatinem/rust-cache@v2.7.5 - - - name: cargo build - run: cargo build --release - - - name: Get package version - run: > - echo "VERSION=$( - cargo metadata --format-version=1 --no-deps | - jq -r '.packages[] | select(.name == "kalatori") | .version' - )" >> $GITHUB_ENV - - - name: Draft release binary - run: gh release create -d $VERSION ./target/release/kalatori --generate-notes \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f7dbaf6..f763d5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,9 +21,4 @@ COPY --from=builder /usr/src/kalatori/target/release/kalatori /app/kalatori EXPOSE 16726 -ENV KALATORI_HOST="0.0.0.0:16726" -ENV KALATORI_SEED="bottom drive obey lake curtain smoke basket hold race lonely fit walk" -ENV KALATORI_RECIPIENT="5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" -ENV KALATORI_REMARK="test" - CMD ["/app/kalatori"]