Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions .github/workflows/build&relase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
name: Build and Release Workflow
on:
push:
paths-ignore:
- '**.md'
- 'docs/**'
- '.gitignore'
pull_request:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
packages: read

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure Git Safe Directory
run: git config --global --add safe.directory $GITHUB_WORKSPACE

- name: Get Go version from go.mod
id: go-version
run: |
GO_VERSION=$(grep -E '^go [0-9]+\.[0-9]+(\.[0-9]+)?$' go.mod | cut -d ' ' -f 2)
echo "Found go directive version: $GO_VERSION"
echo "version=$GO_VERSION" >> $GITHUB_OUTPUT

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ steps.go-version.outputs.version }}
cache: true

- name: Prepare Build Variables
id: vars
run: |
repo_name=${GITHUB_REPOSITORY##*/}

# For non-tag builds, use commit SHA as identifier
build_id=${GITHUB_SHA::7}
echo "build_id=$build_id" >> $GITHUB_OUTPUT
echo "binary_name=supernode-linux-amd64" >> $GITHUB_OUTPUT

# Debug output
echo "Output variables:"
echo "- build_id: $build_id"
echo "- binary_name: supernode-linux-amd64"

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libwebp-dev

- name: Build binary
run: |
mkdir -p release

CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64 \
go build \
-trimpath \
-ldflags="-s -w" \
-o release/${{ steps.vars.outputs.binary_name }} \
./supernode/main.go

# Make binary executable
chmod +x release/${{ steps.vars.outputs.binary_name }}

# Show build results
ls -la release/

# Fix permissions
- name: Fix Release Directory Permissions
run: |
sudo chown -R $USER:$USER release/
sudo chmod -R 755 release/

release:
needs: build
if: startsWith(github.ref, 'refs/tags/v') && (github.ref_type == 'tag') && (contains(github.ref, '.') && (contains(github.ref, 'v')))
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get tag information
id: tag_info
run: |
# Get the tag name
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT

# Get the tag message
TAG_MESSAGE=$(git tag -l --format='%(contents)' $TAG_NAME)
# If tag message is empty, use the tag name as message
if [ -z "$TAG_MESSAGE" ]; then
TAG_MESSAGE="Release $TAG_NAME"
fi
# Handle multiline tag messages
TAG_MESSAGE="${TAG_MESSAGE//'%'/'%25'}"
TAG_MESSAGE="${TAG_MESSAGE//$'\n'/'%0A'}"
TAG_MESSAGE="${TAG_MESSAGE//$'\r'/'%0D'}"
echo "tag_message=$TAG_MESSAGE" >> $GITHUB_OUTPUT

# Get the annotated tag commit
TAG_COMMIT=$(git rev-list -n 1 $TAG_NAME)
echo "tag_commit=$TAG_COMMIT" >> $GITHUB_OUTPUT

- name: Configure Git Safe Directory
run: git config --global --add safe.directory $GITHUB_WORKSPACE

- name: Get Go version from go.mod
id: go-version
run: |
GO_VERSION=$(grep -E '^go [0-9]+\.[0-9]+(\.[0-9]+)?$' go.mod | cut -d ' ' -f 2)
echo "Found go directive version: $GO_VERSION"
echo "version=$GO_VERSION" >> $GITHUB_OUTPUT

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ steps.go-version.outputs.version }}
cache: true

- name: Prepare Release Variables
id: vars
run: |
repo_name=${GITHUB_REPOSITORY##*/}
echo "binary_name=supernode-linux-amd64" >> $GITHUB_OUTPUT

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libwebp-dev

- name: Build Release Version
run: |
mkdir -p release

CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64 \
go build \
-trimpath \
-ldflags="-s -w" \
-o release/${{ steps.vars.outputs.binary_name }} \
./supernode/main.go

# Make binary executable
chmod +x release/${{ steps.vars.outputs.binary_name }}

# Show build results
ls -la release/

# Fix permissions
- name: Fix Release Directory Permissions
run: |
sudo chown -R $USER:$USER release/
sudo chmod -R 755 release/

- name: Publish the Release
uses: softprops/action-gh-release@v0.1.15
if: success()
with:
tag_name: ${{ steps.tag_info.outputs.tag_name }}
files: release/*
generate_release_notes: true
body: |
${{ steps.tag_info.outputs.tag_message }}

Tag: ${{ steps.tag_info.outputs.tag_name }}
Commit: ${{ steps.tag_info.outputs.tag_commit }}

Installation:
1. Download the binary
2. Make it executable: `chmod +x supernode-linux-amd64`
3. Run the binary: `./supernode-linux-amd64`
token: ${{ secrets.GITHUB_TOKEN }}