name: Release
on:
release:
types: [created, edited]
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. v1.2.3). Leave empty to use latest tag."
required: false
jobs:
resolve-tag:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.get-tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve tag
id: get-tag
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
if [ -n "${{ github.event.inputs.tag }}" ]; then
echo "Using manual tag input: ${{ github.event.inputs.tag }}"
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
else
TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "No manual tag input. Using latest tag: $TAG"
echo "tag=$TAG" >> $GITHUB_OUTPUT
fi
elif [ "${{ github.event_name }}" == "release" ]; then
echo "tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
fi
gnu-bash:
needs: resolve-tag
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- run: |
echo ${{ env.TAG }}
- run: |
echo "TAG is: $TAG"
- name: Debug output from resolve-tag
run: echo "Resolved tag is ${{ needs.resolve-tag.outputs.tag }}"
- name: Debug tag
run: echo "ref_name ${{github.ref_name}} | ref_type ${{github.ref_type}}"
- uses: actions/checkout@v4
- name: Install clipboard deps
run: sudo apt install xorg-dev libxcb-composite0-dev
- run: cargo build --target x86_64-unknown-linux-gnu --release
- run: cp target/x86_64-unknown-linux-gnu/release/gpt-cli gpt-cli.gnu
- run: shasum -a 256 gpt-cli.gnu | cut -d " " -f 1 > gpt-cli.gnu.sha256.txt
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
files: |
gpt-cli.gnu
gpt-cli.gnu.sha256.txt
- name: Update fallback release URL
run: sed -i "s|FALLBACK_RELEASE_URL=.*|FALLBACK_RELEASE_URL=https://api.github.com/repos/gustawdaniel/gpt-cli/releases/${{ github.event.release.id }}|" install.sh
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
author_name: Daniel Gustaw
author_email: gustaw.daniel@gmail.com
message: "updated fallback release url to ${{ github.event.release.id }}"
add: 'install.sh'
push: origin HEAD:main
tag_push: '--force'
aur:
needs: gnu-bash
runs-on: ubuntu-latest
container:
image: archlinux:latest
env:
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- name: Install base-devel
run: |
pacman -Syu --noconfirm base-devel wget bc
- name: Derive version values from tag
run: |
echo "PKGVER=$(echo '${TAG}' | sed 's/^v//')" >> $GITHUB_ENV
echo "PKGREL=$(echo "1+$(curl -s "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=gpt-cli" | grep ^pkgrel= | cut -d "=" -f 2)" | bc)" >> $GITHUB_ENV
- name: Use release information
run: |
echo "Using PKGVER: ${PKGVER} and PKGREL: ${PKGREL}"
- run: echo ${{ env.PKGVER }}
- run: echo ${{ env.PKGREL }}
- name: Setup environment2
run: |
wget "https://github.com/gustawdaniel/gpt-cli/releases/download/v${{ env.PKGVER }}/gpt-cli.gnu" -O gpt-cli.gnu
echo "CHECKSUM=$(sha512sum gpt-cli.gnu | cut -d " " -f 1)" >> $GITHUB_ENV
- name: Prepare PKGBUILD
run: |
cat <<EOT >> PKGBUILD
pkgname=gpt-cli
pkgver=${{ env.PKGVER }}
pkgrel=${{ env.PKGREL }}
pkgdesc="Run linux commands with natural language. Eg 'show my graphic card' instead 'lspci | grep VGA'"
arch=('x86_64')
url="https://github.com/gustawdaniel/gpt-cli"
license=('MIT')
depends=('xorg-server-devel' 'libxcb')
options=()
source_x86_64=("https://github.com/gustawdaniel/gpt-cli/releases/download/v${{ env.PKGVER }}/gpt-cli.gnu")
sha512sums_x86_64=('${{ env.CHECKSUM }}')
package() {
install -Dm755 "\$srcdir/gpt-cli.gnu" "\$pkgdir/usr/bin/gpt-cli"
ln -s "/usr/bin/gpt-cli" "\$pkgdir/usr/bin/p"
}
EOT
- name: Generate .SRCINFO
run: |
useradd -m builduser
passwd -d builduser
echo "builduser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/builduser
chown -R builduser:builduser .
sudo -u builduser bash -c "makepkg --printsrcinfo > .SRCINFO"
- name: Show files
run: |
ls -la
cat PKGBUILD
cat .SRCINFO
- name: Publish AUR package
uses: KSXGitHub/github-actions-deploy-aur@v2.7.0
with:
pkgname: gpt-cli
pkgbuild: ./PKGBUILD
commit_username: gustawdaniel
commit_email: gustaw.daniel@gmail.com
ssh_private_key: ${{ secrets.ID_ED25519 }}
commit_message: Release ${{ env.PKGVER }}-${{ env.PKGREL }}
ssh_keyscan_types: ed25519
musl-docker:
needs: resolve-tag
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
- run: sudo apt install musl-tools
- run: rustup target add x86_64-unknown-linux-musl
- run: cargo build --target x86_64-unknown-linux-musl --release
- run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/gpt-cli .
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/gpt-cli
- run: cp target/x86_64-unknown-linux-musl/release/gpt-cli gpt-cli.musl
- run: shasum -a 256 gpt-cli.musl | cut -d " " -f 1 > gpt-cli.musl.sha256.txt
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
files: |
gpt-cli.musl
gpt-cli.musl.sha256.txt
cargo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install clipboard deps
run: sudo apt install xorg-dev libxcb-composite0-dev
- run: cargo build --target x86_64-unknown-linux-gnu --release
- name: Publish if not released
run: |
VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
NAME=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].name')
if curl -sSf https://crates.io/api/v1/crates/$NAME/$VERSION > /dev/null; then
echo "$NAME@$VERSION already exists on crates.io. Skipping publish."
exit 0
fi
cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
deb-rpm:
needs: resolve-tag
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Install nFPM
run: |
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
sudo apt update
sudo apt install -y nfpm shunit2 xorg-dev libxcb-composite0-dev
- run: cargo build --release
- name: Get release information
run: |
RELEASE_TAG=$(echo "${{ env.TAG }}" | sed "s/^v//")
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
- name: Update fallback release URL
run: |
sed -i "s|version: .*|version: \"${{ env.RELEASE_TAG }}\"|" nfpm.yaml
- run: cat nfpm.yaml
- run: nfpm pkg --packager deb --target target
- run: ls -la target
- run: sudo apt install ./target/gpt-cli_${{ env.RELEASE_TAG }}_amd64.deb
- run: ./test_version.sh
- run: nfpm pkg --packager rpm --target target
- run: nfpm pkg --packager archlinux --target target
- name: Compute shasums
run: |
mv ./target/gpt-cli_${{ env.RELEASE_TAG }}_amd64.deb gpt-cli_amd64.deb
mv ./target/gpt-cli-${{ env.RELEASE_TAG }}.x86_64.rpm gpt-cli.x86_64.rpm
mv ./target/gpt-cli-${{ env.RELEASE_TAG }}-1-x86_64.pkg.tar.zst gpt-cli-x86_64.pkg.tar.zst
shasum -a 256 gpt-cli_amd64.deb | cut -d " " -f 1 > gpt-cli_amd64.deb.sha256.txt
shasum -a 256 gpt-cli.x86_64.rpm | cut -d " " -f 1 > gpt-cli.x86_64.rpm.sha256.txt
- run: ls -la
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
files: |
gpt-cli_amd64.deb
gpt-cli.x86_64.rpm
gpt-cli_amd64.deb.sha256.txt
gpt-cli.x86_64.rpm.sha256.txt
gpt-cli-x86_64.pkg.tar.zst
snap:
needs: resolve-tag
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Install shunit
run: sudo apt install -y shunit2
- uses: snapcore/action-build@v1
id: snapcraft
- uses: actions/upload-artifact@v4
with:
name: snap
path: ${{ steps.snapcraft.outputs.snap }}
- run: cp ${{ steps.snapcraft.outputs.snap }} gpt-cli.snap
- run: sudo snap install --dangerous gpt-cli.snap --classic
- run: alias p=gpt-cli
- run: ./test_version.sh
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
files: |
gpt-cli.snap
macos:
needs: resolve-tag
runs-on: macos-latest
permissions:
contents: write
env:
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
- run: cargo build --release
- run: cp target/release/gpt-cli gpt-cli.macos
- run: shasum -a 256 gpt-cli.macos | cut -d " " -f 1 > gpt-cli.macos.sha256.txt
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
files: |
gpt-cli.macos
gpt-cli.macos.sha256.txt