s3-client/.gitea/workflows/build.yaml

165 lines
5.0 KiB
YAML
Raw Normal View History

2024-09-29 03:30:32 +02:00
version: '1'
name: Release Version
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.23.1'
2024-09-29 13:00:48 +02:00
- name: Check if main.go was modified
id: check_main_go
run: |
git fetch origin main
if git diff --name-only HEAD origin/main | grep -q 'main.go'; then
echo "main_go_modified=true" >> $GITHUB_ENV
else
echo "main_go_modified=false" >> $GITHUB_ENV
fi
2024-09-29 04:43:26 +02:00
- name: Build Go binary for Linux
2024-09-29 05:07:22 +02:00
if: env.main_go_modified == 'true'
2024-09-29 03:30:32 +02:00
run: |
go mod tidy
2024-09-29 04:43:26 +02:00
go build -o s3-client_linux.x86_64
2024-09-29 12:45:59 +02:00
- name: Build Go binary for Linux (x86)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOARCH=386 go build -o s3-client_linux.x86
- name: Build Go binary for Linux (ARM64)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOARCH=arm64 go build -o s3-client_linux.arm64
2024-09-29 12:55:58 +02:00
- name: Build Go binary for Mac OS (x86_64)
if: env.main_go_modified == 'true'
run: |
go mod tidy
2024-09-29 13:00:48 +02:00
GOOS=darwin GOARCH=amd64 go build -o s3-client_darwin.x86_64.app
2024-09-29 12:55:58 +02:00
- name: Build Go binary for Mac OS (ARM64)
if: env.main_go_modified == 'true'
run: |
go mod tidy
2024-09-29 12:58:52 +02:00
GOOS=darwin GOARCH=arm64 go build -o s3-client_darwin.arm64.app
2024-09-29 12:55:58 +02:00
2024-09-29 12:45:59 +02:00
- name: Build Go binary for Linux (ARMv7)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOARCH=arm go build -o s3-client_linux.armv7
- name: Build Go binary for Linux (RISC-V)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOARCH=riscv64 go build -o s3-client_linux.riscv64
2024-09-29 04:43:26 +02:00
- name: Build Go binary for Windows
2024-09-29 05:07:22 +02:00
if: env.main_go_modified == 'true'
2024-09-29 04:43:26 +02:00
run: |
GOOS=windows GOARCH=amd64 go build -o s3-client_windows.x86_64.exe
2024-09-29 03:30:32 +02:00
2024-09-29 12:45:59 +02:00
- name: Build Go binary for Windows (x86)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOOS=windows GOARCH=386 go build -o s3-client_windows.x86.exe
- name: Build Go binary for Windows (ARM64)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOOS=windows GOARCH=arm64 go build -o s3-client_windows.arm64.exe
2024-09-29 03:47:23 +02:00
- name: Get latest commit ID
id: get_commit
run: |
commit_id=$(git rev-parse HEAD)
2024-09-29 04:31:47 +02:00
echo "commit_id=$commit_id" >> $GITHUB_ENV
2024-09-29 03:47:23 +02:00
- name: Get latest version and increment
2024-09-29 03:30:32 +02:00
id: create_version
run: |
2024-09-29 05:08:54 +02:00
if [ "${{ env.main_go_modified }}" = "false" ]; then
echo "No changes in main.go, skipping version increment and release creation."
exit 0
fi
2024-09-29 04:50:34 +02:00
git fetch --tags
latest_version=$(git tag | sort -V | tail -n 1 || echo "v0.0.0")
2024-09-29 03:30:32 +02:00
new_version=$(echo $latest_version | awk -F. '{printf "v%d.%d.%d", $1, $2, $3+1}')
2024-09-29 03:47:23 +02:00
2024-09-29 04:46:37 +02:00
while git rev-parse "$new_version" >/dev/null 2>&1; do
new_version=$(echo $new_version | awk -F. '{$3+=1; printf "v%d.%d.%d", $1, $2, $3}')
done
2024-09-29 03:47:23 +02:00
2024-09-29 04:50:34 +02:00
echo "latest_version=$latest_version" >> $GITHUB_ENV
2024-09-29 03:30:32 +02:00
echo "new_version=$new_version" >> $GITHUB_ENV
2024-09-29 04:50:34 +02:00
if git rev-parse "$new_version" >/dev/null 2>&1; then
echo "Tag $new_version already exists. Exiting."
exit 1
fi
2024-09-29 03:30:32 +02:00
git tag $new_version
2024-09-29 04:31:47 +02:00
git push origin $new_version
2024-09-29 03:30:32 +02:00
- name: Create Release
2024-09-29 03:51:20 +02:00
id: create_release
2024-09-29 05:08:54 +02:00
if: env.main_go_modified == 'true'
2024-09-29 03:30:32 +02:00
uses: actions/create-release@v1
with:
tag_name: ${{ env.new_version }}
release_name: Release ${{ env.new_version }}
2024-09-29 03:42:53 +02:00
release_description: |
Automatic release by Gitea CI
Release version ${{ env.new_version }}.
2024-09-29 04:31:47 +02:00
Commit ID: ${{ env.commit_id }}
2024-09-29 03:30:32 +02:00
draft: false
prerelease: false
env:
2024-09-29 04:19:23 +02:00
GITEA_TOKEN: ${{ secrets.TOKEN }}
GITHUB_TOKEN: ${{ secrets.TOKEN }}
2024-09-29 03:30:32 +02:00
2024-09-29 04:43:26 +02:00
- name: Upload Go binaries to release
2024-09-29 05:08:54 +02:00
if: env.main_go_modified == 'true'
2024-09-29 04:30:23 +02:00
uses: softprops/action-gh-release@v1
2024-09-29 03:30:32 +02:00
with:
2024-09-29 04:43:26 +02:00
files: |
./s3-client_linux.x86_64
2024-09-29 12:45:59 +02:00
./s3-client_linux.x86
./s3-client_linux.armv7
./s3-client_linux.arm64
./s3-client_linux.riscv64
2024-09-29 04:43:26 +02:00
./s3-client_windows.x86_64.exe
2024-09-29 12:45:59 +02:00
./s3-client_windows.x86.exe
./s3-client_windows.arm64.exe
2024-09-29 12:58:52 +02:00
./s3-client_darwin.x86_64.app
./s3-client_darwin.arm64.app
2024-09-29 12:45:59 +02:00
2024-09-29 04:36:45 +02:00
tag_name: ${{ env.new_version }}
2024-09-29 04:43:26 +02:00
name: Release ${{ env.new_version }}
body: |
Automatic release by Gitea CI
Release version ${{ env.new_version }}.
Commit ID: ${{ env.commit_id }}
2024-09-29 04:24:02 +02:00
env:
2024-09-29 04:43:26 +02:00
GITHUB_TOKEN: ${{ secrets.TOKEN }}