Skip to content

Commit

Permalink
Update distribute-binaries.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
bearaujus committed Dec 9, 2024
1 parent 599bfac commit 0f92f61
Showing 1 changed file with 66 additions and 21 deletions.
87 changes: 66 additions & 21 deletions .github/workflows/distribute-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,82 @@ jobs:
if: env.skip != 'true'
run: |
sudo apt-get update
sudo apt-get install -y gcc g++ libc6-dev gcc-multilib g++-x86-64-linux-gnu osslsigncode openssl
sudo apt-get install -y gcc g++ libc6-dev gcc-multilib g++-x86-64-linux-gnu libc6-dev-amd64-cross
- name: Build Go binary
- name: Get version from tag
id: get_version
run: |
GOOS=windows GOARCH=amd64 go build -o myapp .
echo "VERSION=$(echo ${GITHUB_REF} | sed 's/refs\/tags\///')" >> $GITHUB_ENV
- name: Import Private Key from GitHub Secrets
if: env.skip != 'true'
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
- name: Get repository name name
id: get_repo_name
run: |
echo "$PRIVATE_KEY" > private.key
chmod 600 private.key
REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f2)
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV
echo "Repository name: ${REPO_NAME}"
- name: Generate Certificate Signing Request (CSR)
env:
REQUEST_CSR_SUBJECT: ${{ secrets.REQUEST_CSR_SUBJECT }}
- name: Build binaries
if: env.skip != 'true'
run: |
openssl req -new -key private.key -out request.csr -subj "$REQUEST_CSR_SUBJECT"
# Define a specific list of GOOS and GOARCH combinations
GOOS_ARCH_LIST=(
"windows/amd64" # 64-bit Windows (most Steam users are on Windows)
"windows/386" # 32-bit Windows (for older or lower-end devices)
"linux/amd64" # 64-bit Linux (commonly used by Steam users on Linux)
"linux/386" # 32-bit Linux (for older or low-resource Linux devices)
"darwin/amd64" # 64-bit macOS (used by some Steam users on macOS)
"darwin/386" # 32-bit macOS (less common, but still used by some legacy systems)
)
- name: Self-Sign the CSR to Create a Certificate
run: |
openssl x509 -req -in request.csr -signkey private.key -out myapp-cert.pem
VERSION=${{ env.VERSION }}
REPO_NAME=${{ env.REPO_NAME }}
- name: Sign Binary with Private Key
run: |
openssl dgst -sha256 -sign private.key -out myapp.sig myapp
# Create a directory for the build outputs
mkdir -p dist
# Loop through the GOOS and GOARCH combinations and build binaries
for GOOS_ARCH in "${GOOS_ARCH_LIST[@]}"; do
GOOS=$(echo $GOOS_ARCH | cut -d'/' -f1)
GOARCH=$(echo $GOOS_ARCH | cut -d'/' -f2)
# Disable cgo for ARM builds
if [[ "$GOOS" == "windows" ]]; then
export CGO_ENABLED=0
else
export CGO_ENABLED=1
fi
# Set environment variables
export GOOS
export GOARCH
# Standardize binary OS name
FILENAME_GOOS=$GOOS
if [[ "$GOOS" == "darwin" ]]; then
FILENAME_GOOS=mac
fi
# Standardize binary architecture
FILENAME_GOARCH=$GOARCH
if [[ "$GOARCH" == "amd64" ]]; then
FILENAME_GOARCH=x64
fi
if [[ "$GOARCH" == "386" ]]; then
FILENAME_GOARCH=x32
fi
# Construct the filename and add .exe for Windows
FILENAME="${REPO_NAME}-${VERSION}-${FILENAME_GOOS}-${FILENAME_GOARCH}"
# Build the binary with the required format and ldflags for version, name, arch, and goos
go build -ldflags "-X main.name=${REPO_NAME} -X main.version=${VERSION} -X main.arch=${GOARCH} -X main.goos=${GOOS} -X main.file=${FILENAME}" -o "dist/${FILENAME}"
echo "Built binary: ${FILENAME}"
done
- name: Upload Signed Binary, Certificate, and Signature
- name: Upload binaries to release
uses: softprops/action-gh-release@v1
with:
files: myapp
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 0f92f61

Please sign in to comment.