fix #76
Workflow file for this run
This file contains 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: Build packages | |
on: | |
push: | |
# tags: | |
# - 'v*.*.*' | |
env: | |
GO_VERSION: "1.20" | |
APP_NAME: "gopssh" | |
MAIN_GO: "cmd/gopssh/main.go" | |
DESC: "parallel ssh client" | |
jobs: | |
info: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get the info | |
id: info | |
run: | | |
ver=$(date "+%y%m.%d.%S") | |
[[ $GITHUB_REF == refs\/tags\/v* ]] && ver=${GITHUB_REF/refs\/tags\/v/} | |
hash=$(git rev-parse --short HEAD) | |
echo ver=$ver hash=$hash | |
echo "ver=$ver" >> $GITHUB_OUTPUT | |
echo "hash=$hash" >> $GITHUB_OUTPUT | |
- name: show info | |
run: | | |
echo "version: ${{ steps.info.outputs.ver }}" >> $GITHUB_STEP_SUMMARY | |
echo "hash: ${{ steps.info.outputs.hash }}" >> $GITHUB_STEP_SUMMARY | |
echo "date: $(date --iso-8601=seconds)" >> $GITHUB_STEP_SUMMARY | |
outputs: | |
ver: ${{ steps.info.outputs.ver }} | |
hash: ${{ steps.info.outputs.hash }} | |
go-test: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: "go.mod" | |
- name: Test | |
run: | | |
go test -v ./... | |
build-binary: | |
runs-on: ubuntu-22.04 | |
needs: [info, go-test] | |
strategy: | |
matrix: | |
goos: [darwin, linux] | |
goarch: [amd64, arm64] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: "go.mod" | |
- name: Build | |
run: | | |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=0 go build -v -ldflags "-X main.version=${{ needs.info.outputs.ver }} -X main.commit=${{ needs.info.outputs.hash }} -X main.date=$(date --iso-8601=seconds)" -o .bin/${{ env.APP_NAME }} ${{ env.MAIN_GO }} | |
ls -la | |
ls -la .bin | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: bin-${{ matrix.goos }}-${{ matrix.goarch }} | |
path: .bin/${{ env.APP_NAME }} | |
# build rpm, deb packages | |
build-linux-packages: | |
runs-on: ubuntu-22.04 | |
needs: [info, build-binary] | |
strategy: | |
matrix: | |
goarch: [amd64, arm64] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version-file: "go.mod" | |
- uses: actions/download-artifact@v4 | |
with: | |
name: bin-linux-${{ matrix.goarch }} | |
path: .bin | |
- name: Build Linux RPM Packages | |
run: | | |
ls -la | |
case ${{ matrix.goarch }} in | |
"amd64") arch=x86_64;; | |
"arm64") arch=aarch64;; | |
esac | |
NAME=${{ env.APP_NAME }} \ | |
VERSION=${{ needs.info.outputs.ver }} \ | |
HASH=${{ needs.info.outputs.hash }} \ | |
ARCH=$arch \ | |
RELEASE=1 \ | |
BINPATH=.bin/${{ env.APP_NAME }} \ | |
go run pack/rpmpack/main.go | |
- name: Build Linux DEB Packages | |
run: | | |
VERSION="${{ needs.info.outputs.ver }}" \ | |
ARCH="${{ matrix.goarch }}" \ | |
NAME="${{ env.APP_NAME }}" \ | |
DESC="${{ env.DESC }}" \ | |
BINPATH=".bin/${{ env.APP_NAME }}" \ | |
go run pack/debpack/main.go | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: linux-packages-${{ matrix.goarch }} | |
path: | | |
./*.rpm | |
./*.deb | |
- name: show info | |
run: | | |
echo "ls -la" >> $GITHUB_STEP_SUMMARY | |
ls -la >> $GITHUB_STEP_SUMMARY | |
create-release: | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-22.04 | |
needs: [info, build-linux-packages] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download All Artifacts | |
uses: actions/download-artifact@v4 | |
- name: Create assets | |
run: | | |
mkdir .dist | |
for os in darwin linux;do | |
for arch in amd64 arm64;do | |
cd bin-${os}-${arch} | |
chmod 755 ${{ env.APP_NAME }} | |
tar -cvzf ../.dist/${os}-${arch}.tar.gz ${{ env.APP_NAME }} | |
cd .. | |
done | |
done | |
for arch in amd64 arm64;do | |
mv linux-packages-${arch}/* .dist | |
done | |
ls -la .dist | |
ls -la .dist>> $GITHUB_STEP_SUMMARY | |
- name: Create release.md | |
run: | | |
cp releasenote.template.md release.md | |
sed -i -e "s/__amd64rpm__/$(basename .dist/*x86_64.rpm)/" release.md | |
sed -i -e "s/__arm64rpm__/$(basename .dist/*aarch64.rpm)/" release.md | |
sed -i -e "s/__amd64deb__/$(basename .dist/*amd64.deb)/" release.md | |
sed -i -e "s/__arm64deb__/$(basename .dist/*arm64.deb)/" release.md | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
prerelease: true | |
body_path: release.md | |
fail_on_unmatched_files: true | |
generate_release_notes: true | |
append_body: true | |
files: | | |
.dist/*.rpm | |
.dist/*.deb | |
.dist/*.tar.gz | |
- name: Create homebrew Formula | |
run: | | |
cp pack/Formula/template.rb gopssh.rb | |
sed -i -e "s/__version__/v${{ needs.info.outputs.ver }}/g" gopssh.rb | |
for os in darwin linux;do | |
for arch in amd64 arm64;do | |
sed -i -e "s/__${os}-${arch}_sha256__/$(sha256sum .dist/${os}-${arch}.tar.gz|awk '{print $1}')/" gopssh.rb | |
done | |
done | |
mkdir -p ~/.ssh/ | |
echo "${{ secrets.BREWREPOKEY }}" >~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519 | |
git config --global user.email "bot@github.com" && git config --global user.name "Github Actions" | |
git clone git@github.com:masahide/homebrew-tap.git && cd homebrew-tap | |
cp ../gopssh.rb Formula/ && git add Formula/gopssh.rb | |
git commit -am"gopssh v${{ needs.info.outputs.ver }}" | |
git push origin main |