Skip to content

update release job. #32

update release job.

update release job. #32

Workflow file for this run

# Copyright (c) 2021 Blacknon. All rights reserved.
# Use of this source code is governed by an MIT license
# that can be found in the LICENSE file.
name: Release Job.
on:
push:
branches:
- master
permissions:
contents: write
jobs:
build:
strategy:
matrix:
include:
- goos: linux
goarch: amd64
os: ubuntu-latest
archive_ext: tar.gz
- goos: darwin
goarch: amd64
os: macos-latest
archive_ext: tar.gz
- goos: darwin
goarch: arm64
os: macos-latest
archive_ext: tar.gz
- goos: windows
goarch: amd64
os: windows-latest
archive_ext: zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Get version
id: package_version
shell: bash
run: |
set -euo pipefail
VERSION="$(go run ./cmd/lssh --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Install nfpm
if: matrix.goos == 'linux'
shell: bash
run: |
set -euo pipefail
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Build binaries
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
set -euo pipefail
mkdir -p dist/bin
ext=""
if [ "${GOOS}" = "windows" ]; then
ext=".exe"
fi
for cmd in lssh lscp lsftp lsmon lsshell; do
go build -o "dist/bin/${cmd}${ext}" "./cmd/${cmd}"
done
- name: Create release packages
shell: bash
env:
VERSION: ${{ steps.package_version.outputs.version }}
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
ARCHIVE_EXT: ${{ matrix.archive_ext }}
run: |
set -euo pipefail
mkdir -p dist/packages dist/nfpm
package_name() {
case "$1" in
full) echo "lssh" ;;
core) echo "lssh-core" ;;
transfer) echo "lssh-transfer" ;;
monitor) echo "lssh-monitor" ;;
sysadmin) echo "lssh-sysadmin" ;;
esac
}
package_description() {
case "$1" in
full) echo "Full lssh suite with SSH, transfer, monitoring, and parallel shell tools." ;;
core) echo "Core SSH client package for the lssh suite." ;;
transfer) echo "Transfer tools package for the lssh suite, including lscp and lsftp." ;;
monitor) echo "Monitoring tools package for the lssh suite, including lsmon." ;;
sysadmin) echo "Sysadmin tools package for the lssh suite, including lsshell." ;;
esac
}
package_binaries() {
case "$1" in
full) echo "lssh lscp lsftp lsmon lsshell" ;;
core) echo "lssh" ;;
transfer) echo "lscp lsftp" ;;
monitor) echo "lsmon" ;;
sysadmin) echo "lsshell" ;;
esac
}
deb_arch() {
case "$1" in
amd64) echo "amd64" ;;
arm64) echo "arm64" ;;
*) echo "$1" ;;
esac
}
rpm_arch() {
case "$1" in
amd64) echo "x86_64" ;;
arm64) echo "aarch64" ;;
*) echo "$1" ;;
esac
}
create_archive() {
local package_id="$1"
local pkg
local base
local root
pkg="$(package_name "$package_id")"
base="${pkg}_${VERSION}_${GOOS}_${GOARCH}"
root="dist/archive/${base}"
rm -rf "$root"
mkdir -p "$root/bin" "$root/completion/zsh"
cp README.md LICENSE.md "$root/"
for bin in $(package_binaries "$package_id"); do
local ext=""
if [ "$GOOS" = "windows" ]; then
ext=".exe"
fi
cp "dist/bin/${bin}${ext}" "$root/bin/${bin}${ext}"
if [ -f "completion/zsh/_${bin}" ]; then
cp "completion/zsh/_${bin}" "$root/completion/zsh/_${bin}"
fi
done
if [ "$GOOS" = "windows" ]; then
powershell -NoLogo -NoProfile -Command "\$source = Join-Path (Get-Location) '${root}'; \$destination = Join-Path (Get-Location) 'dist/packages/${base}.zip'; Compress-Archive -Path (Join-Path \$source '*') -DestinationPath \$destination -Force"
else
tar -C "dist/archive" -czf "dist/packages/${base}.tar.gz" "${base}"
fi
}
create_nfpm_config() {
local package_id="$1"
local pkg
local desc
local config_path
pkg="$(package_name "$package_id")"
desc="$(package_description "$package_id")"
config_path="dist/nfpm/${pkg}.yaml"
cat > "$config_path" <<EOF
name: ${pkg}
arch: $(deb_arch "$GOARCH")
platform: linux
version: ${VERSION}
section: net
priority: optional
maintainer: blacknon <blacknon@orebibou.com>
description: |
${desc}
vendor: blacknon
homepage: https://github.com/blacknon/lssh
license: MIT
contents:
- src: ./README.md
dst: /usr/share/doc/${pkg}/README.md
- src: ./LICENSE.md
dst: /usr/share/doc/${pkg}/LICENSE.md
EOF
for bin in $(package_binaries "$package_id"); do
cat >> "$config_path" <<EOF
- src: ./dist/bin/${bin}
dst: /usr/bin/${bin}
file_info:
mode: 0755
EOF
if [ -f "completion/zsh/_${bin}" ]; then
cat >> "$config_path" <<EOF
- src: ./completion/zsh/_${bin}
dst: /usr/share/zsh/vendor-completions/_${bin}
file_info:
mode: 0644
EOF
fi
done
}
for package_id in full core transfer monitor sysadmin; do
create_archive "$package_id"
if [ "$GOOS" = "linux" ]; then
pkg="$(package_name "$package_id")"
create_nfpm_config "$package_id"
nfpm package --packager deb --config "dist/nfpm/${pkg}.yaml" --target "dist/packages/${pkg}_${VERSION}_$(deb_arch "$GOARCH").deb"
nfpm package --packager rpm --config "dist/nfpm/${pkg}.yaml" --target "dist/packages/${pkg}-${VERSION}-1.$(rpm_arch "$GOARCH").rpm"
fi
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/packages/*
if-no-files-found: error
overwrite: true
create-release:
needs:
- build
runs-on: ubuntu-latest
outputs:
version: ${{ steps.package_version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Get version
id: package_version
shell: bash
run: |
set -euo pipefail
VERSION="$(go run ./cmd/lssh --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.package_version.outputs.version }}
release_name: Version ${{ steps.package_version.outputs.version }}
draft: true
prerelease: false
upload-release:
needs:
- build
- create-release
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
pattern: release-*
path: dist/packages
merge-multiple: true
- name: List build artifact files
shell: bash
run: |
set -euo pipefail
find dist/packages -maxdepth 1 -type f | sort
- name: Upload release assets
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
gh release upload "v${{ needs.create-release.outputs.version }}" dist/packages/* --clobber --repo "${{ github.repository }}"