diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..cd5dc54 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,205 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + container: + image: rust:bookworm + volumes: + - /root/.ssh:/root/.ssh:ro + + steps: + - name: Install tools + run: | + apt-get update + apt-get install -y dpkg-dev git curl openssh-client + cargo install cargo-deb + + - name: Setup SSH + run: | + echo "GIT_SSH_COMMAND=ssh -p 554 -i /root/.ssh/forgejo_runner -o StrictHostKeyChecking=no" >> "$GITHUB_ENV" + + - name: Checkout source + run: | + git clone ssh://git@git-ssh.janvete.com:554/seth/resticview.git src + cd src + git checkout "${{ github.ref_name }}" + + - name: Build release binaries and .deb + working-directory: src + run: | + VERSION=${{ github.ref_name }} + mkdir -p dist + + # Linux amd64 binary + .deb + cargo build --release + cargo deb --no-build + cp target/debian/*.deb dist/ + + STAGING=$(mktemp -d) + cp target/release/resticview "${STAGING}/resticview" + tar -czf "dist/resticview-${VERSION}-linux-amd64.tar.gz" -C "${STAGING}" resticview + rm -rf "${STAGING}" + + # macOS cross-compilation + rustup target add x86_64-apple-darwin aarch64-apple-darwin + cargo install cargo-zigbuild + cargo zigbuild --release --target x86_64-apple-darwin + cargo zigbuild --release --target aarch64-apple-darwin + + for arch in x86_64 aarch64; do + STAGING=$(mktemp -d) + cp "target/${arch}-apple-darwin/release/resticview" "${STAGING}/resticview" + case "$arch" in + x86_64) out_arch=amd64 ;; + aarch64) out_arch=arm64 ;; + esac + tar -czf "dist/resticview-${VERSION}-darwin-${out_arch}.tar.gz" -C "${STAGING}" resticview + rm -rf "${STAGING}" + done + + echo "=== SHA256 checksums ===" + sha256sum dist/* + + - name: Create Forgejo Release + working-directory: src + env: + FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} + FORGEJO_URL: https://git.janvete.com + run: | + VERSION=${{ github.ref_name }} + API="${FORGEJO_URL}/api/v1/repos/seth/resticview" + + RELEASE_JSON=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \ + -H "Content-Type: application/json" \ + -X POST \ + -d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \ + "${API}/releases") + + echo "Create release response: ${RELEASE_JSON}" + RELEASE_ID=$(echo "${RELEASE_JSON}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) + + if [ -z "${RELEASE_ID}" ]; then + echo "Release may already exist, fetching existing release..." + EXISTING=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \ + "${API}/releases/tags/${VERSION}") + echo "Existing release response: ${EXISTING}" + RELEASE_ID=$(echo "${EXISTING}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) + fi + + if [ -z "${RELEASE_ID}" ]; then + echo "Failed to create or fetch release" + exit 1 + fi + + for ARCHIVE in dist/*; do + [ -e "${ARCHIVE}" ] || continue + NAME=$(basename "${ARCHIVE}") + case "${NAME}" in + *.tar.gz) CONTENT_TYPE="application/gzip" ;; + *.deb) CONTENT_TYPE="application/vnd.debian.binary-package" ;; + *) CONTENT_TYPE="application/octet-stream" ;; + esac + curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \ + -H "Content-Type: ${CONTENT_TYPE}" \ + --data-binary "@${ARCHIVE}" \ + "${API}/releases/${RELEASE_ID}/assets?name=${NAME}" + echo "Uploaded ${NAME}" + done + + - name: Update Homebrew tap + working-directory: src + run: | + VERSION=${{ github.ref_name }} + VER=${VERSION#v} + + SHA_DARWIN_ARM64=$(sha256sum dist/resticview-${VERSION}-darwin-arm64.tar.gz | awk '{print $1}') + SHA_DARWIN_AMD64=$(sha256sum dist/resticview-${VERSION}-darwin-amd64.tar.gz | awk '{print $1}') + SHA_LINUX=$(sha256sum dist/resticview-${VERSION}-linux-amd64.tar.gz | awk '{print $1}') + + git clone ssh://git@git-ssh.janvete.com:554/seth/homebrew-tools.git tap + + cat > tap/Formula/resticview.rb << FORMULA + class Resticview < Formula + desc "TUI browser for restic backup repositories" + homepage "https://git.janvete.com/seth/resticview" + version "${VER}" + license "MIT" + head "https://git.janvete.com/seth/resticview.git", branch: "main" + + on_macos do + if Hardware::CPU.arm? + url "https://git.janvete.com/seth/resticview/releases/download/${VERSION}/resticview-${VERSION}-darwin-arm64.tar.gz" + sha256 "${SHA_DARWIN_ARM64}" + else + url "https://git.janvete.com/seth/resticview/releases/download/${VERSION}/resticview-${VERSION}-darwin-amd64.tar.gz" + sha256 "${SHA_DARWIN_AMD64}" + end + end + + on_linux do + if Hardware::CPU.intel? + url "https://git.janvete.com/seth/resticview/releases/download/${VERSION}/resticview-${VERSION}-linux-amd64.tar.gz" + sha256 "${SHA_LINUX}" + end + end + + def install + bin.install "resticview" + end + + test do + assert_match "TUI browser for restic backup repositories", shell_output("#{bin}/resticview --help") + end + end + FORMULA + + cd tap + git config user.email "forgejo-actions[bot]@janvete.com" + git config user.name "forgejo-actions[bot]" + git add Formula/resticview.rb + git commit -m "chore: bump resticview to ${VERSION}" + git push + + - name: Update APT repository + working-directory: src + run: | + VERSION=${{ github.ref_name }} + + git clone ssh://git@git-ssh.janvete.com:554/seth/apt.git apt-repo + cp dist/*.deb apt-repo/ + + cd apt-repo + dpkg-scanpackages . > Packages + gzip -k -f Packages + + cat > Release << RELEASE + Origin: janvete + Label: janvete + Suite: stable + Codename: stable + Version: 1.0 + Architectures: amd64 + Components: main + Description: janvete tools APT repository + Date: $(date -Ru) + RELEASE + + { + echo "SHA256:" + for f in Packages Packages.gz *.deb; do + [ -e "$f" ] || continue + printf " %s %16d %s\n" "$(sha256sum "$f" | cut -d' ' -f1)" "$(stat -c%s "$f")" "$f" + done + } >> Release + + git config user.email "forgejo-actions[bot]@janvete.com" + git config user.name "forgejo-actions[bot]" + git add -A + git commit -m "chore: add resticview ${VERSION}" + git push diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 3b08196..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: Release - -on: - push: - tags: - - 'v*' - workflow_dispatch: - inputs: - tag: - description: 'Tag to release (e.g. v0.1.6)' - required: true - -permissions: - contents: write - -jobs: - build-macos: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - run: cargo build --release - - run: cargo test --release - - run: cargo clippy --release -- -D warnings - - run: cp target/release/resticview target/release/resticview-macos - - uses: actions/upload-artifact@v4 - with: - name: resticview-macos - path: target/release/resticview-macos - - build-linux: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - run: cargo install cargo-deb - - run: cargo build --release - - run: cargo test --release - - run: cargo clippy --release -- -D warnings - - run: cargo deb - - run: cp target/release/resticview target/release/resticview-linux - - uses: actions/upload-artifact@v4 - with: - name: resticview-linux - path: | - target/release/resticview-linux - target/debian/*.deb - - release: - needs: [build-macos, build-linux] - runs-on: ubuntu-latest - steps: - - uses: actions/download-artifact@v4 - with: - name: resticview-macos - path: artifacts/macos - - uses: actions/download-artifact@v4 - with: - name: resticview-linux - path: artifacts/linux - - name: Create Release - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ github.event.inputs.tag || github.ref_name }} - files: | - artifacts/macos/resticview-macos - artifacts/linux/release/resticview-linux - artifacts/linux/debian/*.deb - generate_release_notes: true - overwrite_files: true diff --git a/Cargo.toml b/Cargo.toml index e6aef4d..5111525 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ edition = "2024" authors = ["janvete"] description = "TUI browser for restic backup repositories" license = "MIT" -repository = "https://github.com/janvete/resticview" -homepage = "https://github.com/janvete/resticview" +repository = "https://git.janvete.com/seth/resticview" +homepage = "https://git.janvete.com/seth/resticview" keywords = ["cli", "tui", "restic", "backup"] categories = ["command-line-utilities"]