From 44a3080cd41749c0b1417f48b82163d3edd946f1 Mon Sep 17 00:00:00 2001 From: lgrn <735192+lgrn@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:35:41 +0200 Subject: [PATCH] octet-stream --- .github/workflows/rust.yml | 147 +++++++++++++++---------------------- 1 file changed, 59 insertions(+), 88 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6a1f5f9..ffacfb8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,118 +1,89 @@ name: Release on Push to Main - on: push: branches: - main - jobs: build-linux: runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 - - name: Set up Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable - - name: Build project - run: cargo build --release + - name: Build project + run: cargo build --release - - name: Verify Build Output - run: ls -lh target/release/ + - name: Verify Build Output + run: ls -lh target/release/ - - name: Archive Linux binary - run: | - mkdir -p dist - cp target/release/valheim-motd dist/valheim-motd-linux - tar -czvf dist/valheim-motd-linux.tar.gz -C dist valheim-motd-linux + - name: Archive Linux binary + run: | + tar -czvf valheim-motd-linux.tar.gz target/release/valheim-motd - - name: Upload Linux binary - uses: actions/upload-artifact@v3 - with: - name: linux-binary - path: dist/valheim-motd-linux.tar.gz + - name: Upload Linux binary + uses: actions/upload-artifact@v3 + with: + name: linux-binary + path: valheim-motd-linux.tar.gz build-macos: runs-on: macos-latest steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 - - name: Set up Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable - - name: Build project - run: cargo build --release + - name: Build project + run: cargo build --release - - name: Verify Build Output - run: ls -lh target/release/ + - name: Verify Build Output + run: ls -lh target/release/ - - name: Archive macOS binary - run: | - mkdir -p dist - cp target/release/valheim-motd dist/valheim-motd-macos - tar -czvf dist/valheim-motd-macos.tar.gz -C dist valheim-motd-macos + - name: Archive macOS binary + run: | + tar -czvf valheim-motd-macos.tar.gz target/release/valheim-motd - - name: Upload macOS binary - uses: actions/upload-artifact@v3 - with: - name: macos-binary - path: dist/valheim-motd-macos.tar.gz + - name: Upload macOS binary + uses: actions/upload-artifact@v3 + with: + name: macos-binary + path: valheim-motd-macos.tar.gz release: runs-on: ubuntu-latest needs: [build-linux, build-macos] steps: - - name: Download Linux binary - uses: actions/download-artifact@v3 - with: - name: linux-binary - path: dist - - - name: Download macOS binary - uses: actions/download-artifact@v3 - with: - name: macos-binary - path: dist - - - name: Create Release - env: - TAG_NAME: v$(date +%F) - run: | - # Create a new release - response=$(curl -s -X POST https://api.github.com/repos/lgrn/${{ github.repository }}/releases \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Content-Type: application/json" \ - -d '{ - "tag_name": "'"$TAG_NAME"'", - "target_commitish": "'"${{ github.sha }}"'", - "name": "'"$TAG_NAME"'", - "body": "Automated release for '"$TAG_NAME"'", - "draft": false, - "prerelease": false - }') - - # Extract the release ID - release_id=$(echo "$response" | jq -r '.id') - - # Upload the Linux binary - curl -s -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Content-Type: application/gzip" \ - --data-binary @dist/valheim-motd-linux.tar.gz \ - "https://uploads.github.com/repos/lgrn/${{ github.repository }}/releases/$release_id/assets?name=valheim-motd-linux.tar.gz" - - # Upload the macOS binary - curl -s -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Content-Type: application/gzip" \ - --data-binary @dist/valheim-motd-macos.tar.gz \ - "https://uploads.github.com/repos/lgrn/${{ github.repository }}/releases/$release_id/assets?name=valheim-motd-macos.tar.gz" + - name: Download Linux binary + uses: actions/download-artifact@v3 + with: + name: linux-binary + + - name: Download macOS binary + uses: actions/download-artifact@v3 + with: + name: macos-binary + + - name: Install GitHub CLI + run: sudo apt-get install -y gh + + - name: Authenticate GitHub CLI + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh auth login --with-token <<< "$GITHUB_TOKEN" + + - name: Create Release and Upload Binaries + env: + TAG_NAME: v$(date +%F) + run: | + gh release create $TAG_NAME valheim-motd-linux.tar.gz valheim-motd-macos.tar.gz --title "$TAG_NAME" --notes "Automated release for $TAG_NAME"