Deploy to stage @ 2407-faithful-piranha #144
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
run-name: Deploy to ${{ inputs.env }} @ ${{ inputs.ref }} | |
on: | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: "The ref to deploy" | |
required: true | |
type: string | |
env: | |
description: "The environment to deploy to" | |
required: true | |
type: choice | |
options: | |
- live | |
- stage | |
concurrency: | |
group: release-hops-${{ inputs.env }} | |
cancel-in-progress: true | |
jobs: | |
release-binary: | |
name: Build And Release Binaries | |
strategy: | |
matrix: | |
goos: [linux, windows, darwin] | |
goarch: [amd64, arm64, universal] | |
exclude: | |
- goos: linux | |
goarch: universal | |
- goos: windows | |
goarch: universal | |
- goos: darwin | |
goarch: amd64 | |
- goos: darwin | |
goarch: arm64 | |
include: | |
- runs-on: ubuntu-latest | |
goos: linux | |
goarch: amd64 | |
- runs-on: ubuntu-latest | |
goos: linux | |
goarch: arm64 | |
- runs-on: ubuntu-latest | |
goos: windows | |
goarch: amd64 | |
- runs-on: ubuntu-latest | |
goos: windows | |
goarch: arm64 | |
- runs-on: macos-latest | |
goos: darwin | |
goarch: universal | |
runs-on: ${{ matrix.runs-on }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.ref }} | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.22.x" | |
- name: Build | |
run: | | |
# binary suffix | |
export EXT='' | |
if [ ${{ matrix.goos }} == 'windows' ]; then | |
export EXT='.exe' | |
fi | |
echo "EXT=$EXT" >> "$GITHUB_ENV" | |
if [ ${{ matrix.goos }} == 'darwin' ]; then | |
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=arm64 go build -C cmd/hops -o bin/hops-arm64 & | |
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=amd64 go build -C cmd/hops -o bin/hops-amd64 & | |
# wait for parallel builds to finish | |
wait | |
# create universal binary | |
lipo -create -output cmd/hops/bin/hops${EXT} cmd/hops/bin/hops-arm64 cmd/hops/bin/hops-amd64 | |
rm cmd/hops/bin/hops-arm64 cmd/hops/bin/hops-amd64 | |
else | |
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -C cmd/hops -o bin/hops${EXT} | |
fi | |
- name: Import Code-Signing Certificates for macOS | |
if: matrix.goos == 'darwin' | |
uses: apple-actions/import-codesign-certs@v2 | |
with: | |
p12-file-base64: ${{ secrets.APPLE_CODE_SIGNING_CERTIFICATE_P12_BASE64 }} | |
p12-password: ${{ secrets.APPLE_CODE_SIGNING_CERTIFICATE_P12_PASSWORD }} | |
- name: Sign MacOS executable | |
if: matrix.goos == 'darwin' | |
env: | |
APPLE_CODE_SIGNING_DEVELOPER_ID: ${{ secrets.APPLE_CODE_SIGNING_DEVELOPER_ID }} | |
run: | | |
.github/scripts/codesign.sh cmd/hops/bin/hops${EXT} | |
- name: Prepare for release | |
run: | | |
mkdir -p zip | |
cd cmd/hops/bin | |
zip ../../../zip/hops-${{ matrix.goos }}-${{ matrix.goarch }}.zip hops${EXT} | |
cd ../../../ | |
- name: Sign MacOS zip | |
if: matrix.goos == 'darwin' | |
env: | |
APPLE_CODE_SIGNING_DEVELOPER_ID: ${{ secrets.APPLE_CODE_SIGNING_DEVELOPER_ID }} | |
run: | | |
.github/scripts/codesign.sh zip/hops-${{ matrix.goos }}-${{ matrix.goarch }}.zip | |
- name: Notarize | |
if: matrix.goos == 'darwin' | |
env: | |
APPLE_LOGIN: ${{ secrets.APPLE_LOGIN }} | |
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }} | |
APPLE_NOTARYTOOL_PASSWORD: ${{ secrets.APPLE_NOTARYTOOL_PASSWORD }} | |
run: | | |
.github/scripts/notarize.sh zip/hops-${{ matrix.goos }}-${{ matrix.goarch }}.zip --apple-id ${{ secrets.APPLE_LOGIN }} --team-id ${{ secrets.APPLE_TEAM_ID }} --password ${{ secrets.APPLE_NOTARYTOOL_PASSWORD }} | |
- name: Upload to release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ inputs.ref }} | |
files: | | |
zip/*.zip | |
release-docker: | |
name: Release Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.ref }} | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.22.x" | |
- uses: ko-build/setup-ko@v0.6 | |
env: | |
KO_DOCKER_REPO: hiphops | |
- name: Login to Docker Hub Registry | |
env: | |
docker_token: ${{ secrets.DOCKERHUB_TOKEN }} | |
run: | | |
echo "${docker_token}" | ko login docker.io --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
- name: Build and push (live) | |
if: inputs.env == 'live' | |
run: | | |
cd cmd/hiphops | |
ko build -B \ | |
-t "${{ inputs.ref }},latest" \ | |
--platform "linux/amd64,"linux/arm64" | |
- name: Build and push (stage) | |
if: inputs.env == 'stage' | |
run: | | |
cd cmd/hiphops | |
ko build -B \ | |
-t "alpha-${{ inputs.ref }},alpha" \ | |
--platform "linux/amd64,linux/arm64" |