Release #7
This file contains hidden or 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 | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Tag to release' | |
| required: true | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| jobs: | |
| build: | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| artifact: ehx-linux-x86_64 | |
| cross: false | |
| - os: ubuntu-latest | |
| target: aarch64-unknown-linux-gnu | |
| artifact: ehx-linux-aarch64 | |
| cross: true | |
| - os: macos-14 | |
| target: x86_64-apple-darwin | |
| artifact: ehx-macos-x86_64 | |
| cross: false | |
| - os: macos-14 | |
| target: aarch64-apple-darwin | |
| artifact: ehx-macos-aarch64 | |
| cross: false | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross | |
| if: matrix.cross | |
| run: cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Build (native) | |
| if: "!matrix.cross" | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Build (cross) | |
| if: matrix.cross | |
| run: cross build --release --target ${{ matrix.target }} | |
| - name: Create archive | |
| run: | | |
| cd target/${{ matrix.target }}/release | |
| tar -czvf ../../../${{ matrix.artifact }}.tar.gz ehx bx | |
| cd ../../.. | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact }} | |
| path: ${{ matrix.artifact }}.tar.gz | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Prepare release files | |
| run: | | |
| mkdir -p release | |
| find artifacts -name "*.tar.gz" -exec cp {} release/ \; | |
| ls -la release/ | |
| - name: Build .deb packages | |
| env: | |
| INPUT_TAG: ${{ github.event.inputs.tag }} | |
| run: | | |
| if [ -n "${INPUT_TAG}" ]; then | |
| VERSION="${INPUT_TAG#v}" | |
| else | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| fi | |
| # amd64 .deb | |
| mkdir -p deb-amd64/DEBIAN deb-amd64/usr/bin | |
| tar -xzf release/ehx-linux-x86_64.tar.gz -C deb-amd64/usr/bin/ | |
| chmod 755 deb-amd64/usr/bin/ehx deb-amd64/usr/bin/bx | |
| cat > deb-amd64/DEBIAN/control << EOF | |
| Package: ehx | |
| Version: ${VERSION} | |
| Section: editors | |
| Priority: optional | |
| Architecture: amd64 | |
| Maintainer: sanohiro <sanohiro@users.noreply.github.com> | |
| Description: Terminal hex editor with Emacs keybindings | |
| A terminal hex editor for those who think in C-x C-s. | |
| EOF | |
| sed -i 's/^ //' deb-amd64/DEBIAN/control | |
| dpkg-deb --build deb-amd64 release/ehx_amd64.deb | |
| # arm64 .deb | |
| mkdir -p deb-arm64/DEBIAN deb-arm64/usr/bin | |
| tar -xzf release/ehx-linux-aarch64.tar.gz -C deb-arm64/usr/bin/ | |
| chmod 755 deb-arm64/usr/bin/ehx deb-arm64/usr/bin/bx | |
| cat > deb-arm64/DEBIAN/control << EOF | |
| Package: ehx | |
| Version: ${VERSION} | |
| Section: editors | |
| Priority: optional | |
| Architecture: arm64 | |
| Maintainer: sanohiro <sanohiro@users.noreply.github.com> | |
| Description: Terminal hex editor with Emacs keybindings | |
| A terminal hex editor for those who think in C-x C-s. | |
| EOF | |
| sed -i 's/^ //' deb-arm64/DEBIAN/control | |
| dpkg-deb --build deb-arm64 release/ehx_arm64.deb | |
| ls -la release/ | |
| - name: Generate checksums | |
| run: | | |
| cd release | |
| sha256sum *.tar.gz *.deb > checksums.txt | |
| cat checksums.txt | |
| - name: Generate Homebrew formula | |
| env: | |
| INPUT_TAG: ${{ github.event.inputs.tag }} | |
| run: | | |
| if [ -n "${INPUT_TAG}" ]; then | |
| VERSION="${INPUT_TAG#v}" | |
| else | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| fi | |
| cd release | |
| SHA_MACOS_ARM=$(sha256sum ehx-macos-aarch64.tar.gz | cut -d' ' -f1) | |
| SHA_MACOS_INTEL=$(sha256sum ehx-macos-x86_64.tar.gz | cut -d' ' -f1) | |
| SHA_LINUX_ARM=$(sha256sum ehx-linux-aarch64.tar.gz | cut -d' ' -f1) | |
| SHA_LINUX_INTEL=$(sha256sum ehx-linux-x86_64.tar.gz | cut -d' ' -f1) | |
| sed -e "s/{{VERSION}}/${VERSION}/g" \ | |
| -e "s/{{SHA_MACOS_ARM}}/${SHA_MACOS_ARM}/g" \ | |
| -e "s/{{SHA_MACOS_INTEL}}/${SHA_MACOS_INTEL}/g" \ | |
| -e "s/{{SHA_LINUX_ARM}}/${SHA_LINUX_ARM}/g" \ | |
| -e "s/{{SHA_LINUX_INTEL}}/${SHA_LINUX_INTEL}/g" \ | |
| ../.github/ehx.rb.template > ehx.rb | |
| cat ehx.rb | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.event.inputs.tag || github.ref_name }} | |
| files: release/* | |
| generate_release_notes: true | |
| draft: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update Homebrew tap | |
| env: | |
| HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| INPUT_TAG: ${{ github.event.inputs.tag }} | |
| run: | | |
| if [ -z "${HOMEBREW_TAP_TOKEN}" ]; then | |
| echo "HOMEBREW_TAP_TOKEN not set, skipping Homebrew tap update" | |
| exit 0 | |
| fi | |
| if [ -n "${INPUT_TAG}" ]; then | |
| VERSION="${INPUT_TAG#v}" | |
| else | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| fi | |
| git clone https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/sanohiro/homebrew-ehx.git | |
| mkdir -p homebrew-ehx/Formula | |
| cp release/ehx.rb homebrew-ehx/Formula/ | |
| cd homebrew-ehx | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Formula/ehx.rb | |
| git diff --cached --quiet || git commit -m "Update ehx to ${VERSION}" | |
| git push | |
| - name: Update apt repository | |
| env: | |
| APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }} | |
| INPUT_TAG: ${{ github.event.inputs.tag }} | |
| run: | | |
| if [ -z "${APT_GPG_PRIVATE_KEY}" ]; then | |
| echo "APT_GPG_PRIVATE_KEY not set, skipping apt repo update" | |
| exit 0 | |
| fi | |
| if [ -n "${INPUT_TAG}" ]; then | |
| VERSION="${INPUT_TAG#v}" | |
| else | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| fi | |
| echo "${APT_GPG_PRIVATE_KEY}" | gpg --batch --import | |
| mkdir -p apt-repo/pool/main/e/ehx | |
| mkdir -p apt-repo/dists/stable/main/binary-amd64 | |
| mkdir -p apt-repo/dists/stable/main/binary-arm64 | |
| cp release/ehx_amd64.deb apt-repo/pool/main/e/ehx/ | |
| cp release/ehx_arm64.deb apt-repo/pool/main/e/ehx/ | |
| cd apt-repo | |
| dpkg-scanpackages --arch amd64 pool/ > dists/stable/main/binary-amd64/Packages | |
| dpkg-scanpackages --arch arm64 pool/ > dists/stable/main/binary-arm64/Packages | |
| gzip -k dists/stable/main/binary-amd64/Packages | |
| gzip -k dists/stable/main/binary-arm64/Packages | |
| cat > dists/stable/Release << EOF | |
| Origin: ehx | |
| Label: ehx | |
| Suite: stable | |
| Codename: stable | |
| Date: $(date -Ru) | |
| Architectures: amd64 arm64 | |
| Components: main | |
| Description: ehx apt repository | |
| EOF | |
| sed -i 's/^ //' dists/stable/Release | |
| cd dists/stable | |
| echo "MD5Sum:" >> Release | |
| for f in main/binary-*/Packages*; do | |
| echo " $(md5sum $f | cut -d' ' -f1) $(wc -c < $f) $f" >> Release | |
| done | |
| echo "SHA256:" >> Release | |
| for f in main/binary-*/Packages*; do | |
| echo " $(sha256sum $f | cut -d' ' -f1) $(wc -c < $f) $f" >> Release | |
| done | |
| cd ../.. | |
| gpg --batch --yes --armor --detach-sign -o dists/stable/Release.gpg dists/stable/Release | |
| gpg --batch --yes --armor --clearsign -o dists/stable/InRelease dists/stable/Release | |
| gpg --armor --export > ehx.gpg | |
| cp ../.github/install.sh . | |
| ls -laR | |
| - name: Deploy apt repo to GitHub Pages | |
| env: | |
| APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }} | |
| if: env.APT_GPG_PRIVATE_KEY != '' | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./apt-repo | |
| publish_branch: gh-pages | |
| force_orphan: true |