name: Build and Release on: push: tags: - 'v*' workflow_dispatch: inputs: version: description: 'Version to release (e.g., v0.1.0)' required: true default: 'v0.1.0' jobs: build-and-release: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Rust uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - name: Install system dependencies run: | apt-get update apt-get install -y pkg-config libssl-dev - name: Build static binary run: | export RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-unknown-linux-gnu - name: Create release directory run: | mkdir -p release cp target/x86_64-unknown-linux-gnu/release/cm-player release/cm-player-linux-x86_64 - name: Create tarball run: | cd release tar -czf cm-player-linux-x86_64.tar.gz cm-player-linux-x86_64 - name: Set version variable id: version run: | if [ "${{ gitea.event_name }}" == "workflow_dispatch" ]; then echo "VERSION=${{ gitea.event.inputs.version }}" >> $GITHUB_OUTPUT else echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT fi - name: Create Release with curl env: GITEA_TOKEN: ${{ secrets.GITEATOKEN }} run: | VERSION="${{ steps.version.outputs.VERSION }}" # Create release curl -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "tag_name": "'$VERSION'", "name": "cm-player '$VERSION'", "body": "## cm-player '$VERSION'\n\nPre-built static binary for Linux x86_64:\n- cm-player-linux-x86_64 - Music and video TUI player\n- cm-player-linux-x86_64.tar.gz - Tarball" }' \ "https://gitea.cmtec.se/api/v1/repos/cm/cm-player/releases" # Get release ID RELEASE_ID=$(curl -s -H "Authorization: token $GITEA_TOKEN" \ "https://gitea.cmtec.se/api/v1/repos/cm/cm-player/releases/tags/$VERSION" | \ grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2) # Upload binaries curl -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -F "attachment=@release/cm-player-linux-x86_64" \ "https://gitea.cmtec.se/api/v1/repos/cm/cm-player/releases/$RELEASE_ID/assets?name=cm-player-linux-x86_64" curl -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -F "attachment=@release/cm-player-linux-x86_64.tar.gz" \ "https://gitea.cmtec.se/api/v1/repos/cm/cm-player/releases/$RELEASE_ID/assets?name=cm-player-linux-x86_64.tar.gz" - name: Update NixOS Configuration env: GITEA_TOKEN: ${{ secrets.GITEATOKEN }} run: | VERSION="${{ steps.version.outputs.VERSION }}" # Clone nixosbox repository git clone https://$GITEA_TOKEN@gitea.cmtec.se/cm/nixosbox.git nixosbox-update cd nixosbox-update # Get hash for the new release tarball TARBALL_URL="https://gitea.cmtec.se/cm/cm-player/releases/download/$VERSION/cm-player-linux-x86_64.tar.gz" # Download tarball to get correct hash curl -L -o cm-player.tar.gz "$TARBALL_URL" # Convert sha256 hex to base64 for Nix hash format using Python NEW_HASH=$(sha256sum cm-player.tar.gz | cut -d' ' -f1) NIX_HASH="sha256-$(python3 -c "import base64, binascii; print(base64.b64encode(binascii.unhexlify('$NEW_HASH')).decode())")" # Update the NixOS configuration sed -i "s|version = \"v[^\"]*\"|version = \"$VERSION\"|" hosts/common/cm-player.nix sed -i "s|sha256 = \"sha256-[^\"]*\"|sha256 = \"$NIX_HASH\"|" hosts/common/cm-player.nix # Commit and push changes git config user.name "Gitea Actions" git config user.email "actions@gitea.cmtec.se" git add hosts/common/cm-player.nix git commit -m "Auto-update cm-player to $VERSION - Update version to $VERSION with automated release - Update tarball hash for new static binary - Automated update from cm-player release workflow" git push