12 Commits

Author SHA1 Message Date
dd3de165f7 Release v1.0.27
All checks were successful
Release Build / create-release-branch (push) Successful in 8s
2025-07-28 11:46:04 +06:00
7c3d490685 Release v1.0.26
All checks were successful
Release Build / create-docker-image (push) Successful in 3m33s
Release Build / create-release (push) Successful in 7m43s
2025-07-28 10:47:23 +06:00
aff61e32fc Release v1.0.0 2025-07-28 10:46:51 +06:00
1a0207017a Release v1.0.25
Some checks failed
Release Build / create-docker-image (push) Successful in 3m30s
Release Build / create-release (push) Failing after 0s
2025-07-28 10:16:51 +06:00
638dc104f8 Release v1.0.0 2025-07-28 10:13:37 +06:00
8b420c500f Remove bin/hello-api-1.0.0 from repository (already in .gitignore) 2025-07-28 10:06:36 +06:00
078c32b929 merged 2025-07-28 10:04:02 +06:00
e4a2fccef4 init local 2025-07-28 09:56:39 +06:00
bde6e734b3 finish working on the article - need test workflows
All checks were successful
Release Build / create-builder-docker-image (push) Successful in 3m45s
2025-07-28 00:38:46 +06:00
e018e30975 working on the article 2025-07-27 21:21:39 +06:00
bf25c33b3f Исправлен workflow - 21 для сборки и релиза
All checks were successful
Release Build / create-docker-image (push) Successful in 4m28s
Release Build / create-release (push) Successful in 6m3s
2025-07-27 15:31:50 +06:00
c1e0f6e04f Исправлен workflow - 20 для сборки и релиза
Some checks failed
Release Build / release (push) Successful in 1m39s
Release Build / create-docker-image (push) Failing after 49s
Release Build / create-release (push) Has been skipped
2025-07-27 15:08:50 +06:00
12 changed files with 2310 additions and 167 deletions

View File

@@ -1,59 +0,0 @@
name: Release Build
on:
push:
tags:
- v*
jobs:
release:
runs-on: ubuntu-latest
container:
image: golang:1.21
steps:
- name: Checkout repository
run: |
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
cd hello_gitea
git checkout ${{ github.ref }}
- name: Setup Go
run: |
# Install jq for JSON parsing
apt-get update && apt-get install -y jq
git --version
go version
jq --version
- name: Build
run: |
cd hello_gitea
mkdir -p bin
go build -o bin/hello-api-${{ github.ref_name }} main.go
ls -la bin/
- name: Create Release
run: |
cd hello_gitea
# Create release using Gitea API
curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "${{ github.ref_name }}",
"name": "Release ${{ github.ref_name }}",
"body": "Automated release",
"draft": false,
"prerelease": false
}' \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases"
# Upload asset
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/tags/${{ github.ref_name }}" | \
jq -r '.id')
curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @bin/hello-api-${{ github.ref_name }} \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=hello-api-${{ github.ref_name }}"

View File

@@ -5,12 +5,132 @@ on:
- v* - v*
jobs: jobs:
create-docker-image: # create-release:
# runs-on: ubuntu-latest
# container:
# # image: golang:1.21
# image: ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:latest
# needs: create-release-branch
# steps:
# - name: Checkout repository
# run: |
# git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
# cd hello_gitea
# git checkout ${{ github.ref }}
# - name: Setup Go
# run: |
# # Install jq for JSON parsing
# apt-get update && apt-get install -y jq
# git --version
# go version
# jq --version
# - name: Build all binaries
# run: |
# cd hello_gitea
# mkdir -p bin
# # Build for all platforms
# GOOS=linux GOARCH=amd64 go build -o bin/hello-api-linux-amd64 main.go
# GOOS=linux GOARCH=arm64 go build -o bin/hello-api-linux-arm64 main.go
# GOOS=windows GOARCH=amd64 go build -o bin/hello-api-windows-amd64.exe main.go
# GOOS=darwin GOARCH=amd64 go build -o bin/hello-api-darwin-amd64 main.go
# GOOS=darwin GOARCH=arm64 go build -o bin/hello-api-darwin-arm64 main.go
# # Create archives
# cd bin
# tar -czf hello-api-linux-amd64.tar.gz hello-api-linux-amd64
# tar -czf hello-api-linux-arm64.tar.gz hello-api-linux-arm64
# tar -czf hello-api-windows-amd64.tar.gz hello-api-windows-amd64.exe
# tar -czf hello-api-darwin-amd64.tar.gz hello-api-darwin-amd64
# tar -czf hello-api-darwin-arm64.tar.gz hello-api-darwin-arm64
# ls -la
# - name: Create Release
# run: |
# cd hello_gitea
# # Create release using Gitea API
# curl -X POST \
# -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
# -H "Content-Type: application/json" \
# -d '{
# "tag_name": "${{ github.ref_name }}",
# "name": "Release ${{ github.ref_name }}",
# "body": "Automated release with multi-platform binaries and Docker image",
# "draft": false,
# "prerelease": false
# }' \
# "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases"
# # Upload assets
# RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
# "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/tags/${{ github.ref_name }}" | \
# jq -r '.id')
# # Upload all binaries
# for file in bin/*.tar.gz; do
# echo "Uploading $file..."
# curl -X POST \
# -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
# -H "Content-Type: application/octet-stream" \
# --data-binary @$file \
# "https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=$(basename $file)"
# done
# create-docker-image:
# runs-on: ubuntu-latest
# container:
# image: docker:28.3.2-dind
# needs: create-release
# steps:
# - name: Checkout repository
# run: |
# # Install git
# apk add --no-cache git
# echo "=== GitHub Variables ==="
# echo "github.ref = ${{ github.ref }}"
# echo "github.ref_name = ${{ github.ref_name }}"
# echo "github.sha = ${{ github.sha }}"
# echo "github.repository = ${{ github.repository }}"
# echo "========================"
# git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
# cd hello_gitea
# git checkout ${{ github.ref }}
# - name: Setup Docker Buildx
# run: |
# # Docker is already installed in docker:dind image
# docker --version
# # Setup Docker Buildx for multi-platform builds
# docker buildx create --use
# docker buildx inspect --bootstrap
# - name: Login to Docker Hub
# run: |
# echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
# - name: Build multi-platform Docker images
# run: |
# cd hello_gitea
# # Build multi-platform images using buildx
# docker buildx build \
# --platform linux/amd64,linux/arm64 \
# --tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:${{ github.ref_name }} \
# --tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest \
# --push \
# .
create-release-branch:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: golang:1.21 image: docker:28.3.2-dind
# needs: create-docker-image
steps: steps:
- name: Checkout repository - name: Create Release Branch
run: | run: |
echo "=== GitHub Variables ===" echo "=== GitHub Variables ==="
echo "github.ref = ${{ github.ref }}" echo "github.ref = ${{ github.ref }}"
@@ -18,104 +138,32 @@ jobs:
echo "github.sha = ${{ github.sha }}" echo "github.sha = ${{ github.sha }}"
echo "github.repository = ${{ github.repository }}" echo "github.repository = ${{ github.repository }}"
echo "========================" echo "========================"
# Clone repository
echo "Cloning repository..."
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
cd hello_gitea cd hello_gitea
git checkout ${{ github.ref }}
- name: Setup Docker Buildx # Configure git
run: | echo "Configuring git..."
# Install Docker CLI git config user.email "info@direct-dev.ru"
apt-get update && apt-get install -y docker.io git config user.name "Direct-Dev-Robot"
docker --version
# Setup Docker Buildx for multi-platform builds # Check if release branch exists
docker buildx create --name multiplatform --use echo "Checking if release branch exists..."
docker buildx inspect --bootstrap if git ls-remote --heads origin release | grep -q release; then
echo "Release branch exists, checking out..."
git checkout release
echo "release branch exists - pulling release branch..."
git pull origin release
else
echo "release branch does not exist - creating new release branch..."
git checkout -b release
fi
- name: Login to Docker Hub # Reset to the tag commit
run: | echo "Resetting to the tag commit ${{ github.ref_name }} ..."
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin git reset --hard ${{ github.ref_name }}
- name: Build multi-platform Docker images # Push changes to release branch
run: | echo "Pushing changes to release branch..."
cd hello_gitea git push origin release --force
# Build multi-platform images using buildx
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:${{ github.ref_name }} \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest \
--push \
.
create-release:
runs-on: ubuntu-latest
container:
image: golang:1.21
needs: create-docker-image
steps:
- name: Checkout repository
run: |
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
cd hello_gitea
git checkout ${{ github.ref }}
- name: Setup Go
run: |
# Install jq for JSON parsing
apt-get update && apt-get install -y jq
git --version
go version
jq --version
- name: Build all binaries
run: |
cd hello_gitea
mkdir -p bin
# Build for all platforms
GOOS=linux GOARCH=amd64 go build -o bin/hello-api-linux-amd64 main.go
GOOS=linux GOARCH=arm64 go build -o bin/hello-api-linux-arm64 main.go
GOOS=windows GOARCH=amd64 go build -o bin/hello-api-windows-amd64.exe main.go
GOOS=darwin GOARCH=amd64 go build -o bin/hello-api-darwin-amd64 main.go
GOOS=darwin GOARCH=arm64 go build -o bin/hello-api-darwin-arm64 main.go
# Create archives
cd bin
tar -czf hello-api-linux-amd64.tar.gz hello-api-linux-amd64
tar -czf hello-api-linux-arm64.tar.gz hello-api-linux-arm64
tar -czf hello-api-windows-amd64.tar.gz hello-api-windows-amd64.exe
tar -czf hello-api-darwin-amd64.tar.gz hello-api-darwin-amd64
tar -czf hello-api-darwin-arm64.tar.gz hello-api-darwin-arm64
ls -la
- name: Create Release
run: |
cd hello_gitea
# Create release using Gitea API
curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "${{ github.ref_name }}",
"name": "Release ${{ github.ref_name }}",
"body": "Automated release with multi-platform binaries and Docker image",
"draft": false,
"prerelease": false
}' \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases"
# Upload assets
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/tags/${{ github.ref_name }}" | \
jq -r '.id')
# Upload all binaries
for file in bin/*.tar.gz; do
echo "Uploading $file..."
curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @$file \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=$(basename $file)"
done

View File

@@ -0,0 +1,51 @@
name: Release Build
on:
push:
tags:
- builder-*
jobs:
create-builder-docker-image:
runs-on: ubuntu-latest
container:
image: docker:28.3.2-dind
steps:
- name: Checkout repository
run: |
# Install git
apk add --no-cache git
echo "=== GitHub Variables ==="
echo "github.ref = ${{ github.ref }}"
echo "github.ref_name = ${{ github.ref_name }}"
echo "github.sha = ${{ github.sha }}"
echo "github.repository = ${{ github.repository }}"
echo "========================"
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
cd hello_gitea
git checkout ${{ github.ref }}
- name: Setup Docker Buildx
run: |
# Docker is already installed in docker:dind image
docker --version
# Setup Docker Buildx for multi-platform builds
docker buildx create --use
docker buildx inspect --bootstrap
- name: Login to Docker Hub
run: |
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Build multi-platform Docker images
run: |
cd hello_gitea
# Build multi-platform images using buildx
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:${{ github.ref_name }} \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:latest \
--push \
-f Dockerfile.builder \
.

13
Dockerfile.builder Normal file
View File

@@ -0,0 +1,13 @@
# Используем образ Go с поддержкой мультиплатформенности
FROM golang:1.24
# Устанавливаем пакеты (одинаково работают на amd64/arm64)
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
ca-certificates \
jq && \
rm -rf /var/lib/apt/lists/*
# (Опционально) Можно добавить команду по умолчанию
CMD ["bash"]

169
README.md
View File

@@ -1,3 +1,168 @@
# hello_gitea # Hello Gitea API
test repo to try with actions - v1.0.11 Простой REST API сервер, построенный на Go с использованием Gin framework.
## 🚀 Возможности
- ✅ REST API с JSON ответами
- ✅ Health check endpoint
- ✅ CORS поддержка
- ✅ Мультиплатформенная сборка
- ✅ Docker образы для Linux AMD64/ARM64
- ✅ Автоматические релизы через Gitea Actions
## 📦 Установка
### Из бинарного файла
1. Скачайте бинарный файл для вашей платформы из [релизов](https://direct-dev.ru/gitea/GiteaAdmin/hello_gitea/releases)
2. Распакуйте архив
3. Запустите: `./hello-api-<platform>`
### Из Docker образа
```bash
docker pull <username>/hello-api:latest
docker run -p 8080:8080 <username>/hello-api:latest
```
### Из исходного кода
```bash
git clone https://direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git
cd hello_gitea
go mod download
go run main.go
```
## 🔧 Конфигурация
Сервер запускается на порту 8080 по умолчанию. Можно изменить через переменную окружения:
```bash
export PORT=3000
./hello-api
```
## 📡 API Endpoints
### GET /
Основной endpoint
**Ответ:**
```json
{
"message": "Hello, World!",
"version": "1.0.0"
}
```
### GET /health
Health check endpoint
**Ответ:**
```json
{
"status": "ok",
"version": "1.0.0"
}
```
### GET /api/v1/info
Информация о сервисе
**Ответ:**
```json
{
"service": "hello-api",
"status": "running",
"version": "1.0.0"
}
```
### POST /api/v1/echo
Echo endpoint - возвращает отправленное сообщение
**Запрос:**
```json
{
"message": "Hello from client!"
}
```
**Ответ:**
```json
{
"echo": "Hello from client!",
"version": "1.0.0"
}
```
## 🛠 Разработка
### Зависимости
- Go 1.21+
- Gin framework
### Сборка
```bash
# Для текущей платформы
go build -o hello-api main.go
# Для Linux AMD64
GOOS=linux GOARCH=amd64 go build -o hello-api-linux-amd64 main.go
# Для Linux ARM64
GOOS=linux GOARCH=arm64 go build -o hello-api-linux-arm64 main.go
# Для Windows
GOOS=windows GOARCH=amd64 go build -o hello-api-windows-amd64.exe main.go
# Для macOS
GOOS=darwin GOARCH=amd64 go build -o hello-api-darwin-amd64 main.go
GOOS=darwin GOARCH=arm64 go build -o hello-api-darwin-arm64 main.go
```
### Тестирование
```bash
# Запуск сервера
go run main.go
# Тестирование API
curl http://localhost:8080/
curl http://localhost:8080/health
curl http://localhost:8080/api/v1/info
curl -X POST http://localhost:8080/api/v1/echo \
-H "Content-Type: application/json" \
-d '{"message":"Hello!"}'
```
## 🚀 CI/CD
При создании тега (например, `v1.1.20`) автоматически:
1. Собираются бинарники для всех платформ
2. Создается Docker образ для Linux AMD64/ARM64
3. Образ публикуется в Docker Hub
4. Создается релиз в Gitea с бинарниками
Дополнительно `.gitea/workflows/build_build.yaml` предназначен для автоматизации процесса сборки и публикации Docker-образов билдера - то есть образа который будет использоваться в основном процессе сборки и релиза. Этот workflow запускается (триггерится) автоматически при пуше тега, начинающегося с `builder-` (например, `builder-v1.2.3`), в репозиторий на сервере Gitea.
Когда такой тег появляется, workflow выполняет следующие задачи:
- Клонирует репозиторий и переключается на соответствующую версию кода.
- Настраивает окружение для сборки Docker-образов с поддержкой мультиплатформенности (amd64 и arm64).
- Выполняет аутентификацию в Docker Hub.
- Собирает и публикует Docker-образы для разных архитектур (tag DOCKERHUB_USERNAME/my-build-golang-runnerr:builder-v1.2.3 и tag DOCKERHUB_USERNAME/my-build-golang-runner:latest.
- Для сборки используется специальный Dockerfile (`Dockerfile.builder`) для создания образа билдера.
Таким образом, данный файл обеспечивает автоматическую сборку и публикацию артефактов проекта при выпуске новых версий, что упрощает процесс релиза и гарантирует наличие актуальных образов и бинарников для пользователей.
## 📄 Лицензия
MIT License

Binary file not shown.

8
build-builder.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag "${DOCKERHUB_USERNAME:-kuznetcovay}"/my-build-golang-runner:latest \
--push \
-f Dockerfile_for_runner_image \
.

124
build.yaml Normal file
View File

@@ -0,0 +1,124 @@
name: Release Build
on:
push:
tags:
- v*
jobs:
create-docker-image:
runs-on: ubuntu-latest
container:
image: docker:28.3.2-dind
steps:
- name: Checkout repository
run: |
# Install git
apk add --no-cache git
echo "=== GitHub Variables ==="
echo "github.ref = ${{ github.ref }}"
echo "github.ref_name = ${{ github.ref_name }}"
echo "github.sha = ${{ github.sha }}"
echo "github.repository = ${{ github.repository }}"
echo "========================"
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
cd hello_gitea
git checkout ${{ github.ref }}
- name: Setup Docker Buildx
run: |
# Docker is already installed in docker:dind image
docker --version
# Setup Docker Buildx for multi-platform builds
docker buildx create --use
docker buildx inspect --bootstrap
- name: Login to Docker Hub
run: |
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Build multi-platform Docker images
run: |
cd hello_gitea
# Build multi-platform images using buildx
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:${{ github.ref_name }} \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/hello-api:latest \
--push \
.
create-release:
runs-on: ubuntu-latest
container:
# image: golang:1.21
image: ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:latest
needs: create-docker-image
steps:
- name: Checkout repository
run: |
git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
cd hello_gitea
git checkout ${{ github.ref }}
- name: Setup Go
run: |
# Install jq for JSON parsing
apt-get update && apt-get install -y jq
git --version
go version
jq --version
- name: Build all binaries
run: |
cd hello_gitea
mkdir -p bin
# Build for all platforms
GOOS=linux GOARCH=amd64 go build -o bin/hello-api-linux-amd64 main.go
GOOS=linux GOARCH=arm64 go build -o bin/hello-api-linux-arm64 main.go
GOOS=windows GOARCH=amd64 go build -o bin/hello-api-windows-amd64.exe main.go
GOOS=darwin GOARCH=amd64 go build -o bin/hello-api-darwin-amd64 main.go
GOOS=darwin GOARCH=arm64 go build -o bin/hello-api-darwin-arm64 main.go
# Create archives
cd bin
tar -czf hello-api-linux-amd64.tar.gz hello-api-linux-amd64
tar -czf hello-api-linux-arm64.tar.gz hello-api-linux-arm64
tar -czf hello-api-windows-amd64.tar.gz hello-api-windows-amd64.exe
tar -czf hello-api-darwin-amd64.tar.gz hello-api-darwin-amd64
tar -czf hello-api-darwin-arm64.tar.gz hello-api-darwin-arm64
ls -la
- name: Create Release
run: |
cd hello_gitea
# Create release using Gitea API
curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "${{ github.ref_name }}",
"name": "Release ${{ github.ref_name }}",
"body": "Automated release with multi-platform binaries and Docker image",
"draft": false,
"prerelease": false
}' \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases"
# Upload assets
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITEATOKEN }}" \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/tags/${{ github.ref_name }}" | \
jq -r '.id')
# Upload all binaries
for file in bin/*.tar.gz; do
echo "Uploading $file..."
curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @$file \
"https://direct-dev.ru/gitea/api/v1/repos/GiteaAdmin/hello_gitea/releases/$RELEASE_ID/assets?name=$(basename $file)"
done

1647
docs/gitea-actions-guide.md Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
const version = "1.0.0" const version = "1.0.27"
func main() { func main() {
// Set Gin mode // Set Gin mode

View File

@@ -1,8 +1,8 @@
.PHONY: build clean test .PHONY: build clean test release
BIN_DIR=bin BIN_DIR=bin
APP_NAME=hello-api APP_NAME=hello-api
VERSION=1.0.0 VERSION=1.0.27
build: build:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
@@ -13,3 +13,16 @@ clean:
test: test:
go test -v ./... go test -v ./...
# Задача для создания релиза
# Использование: make release VERSION=1.0.25
release:
@if [ -z "$(VERSION)" ]; then \
echo "Ошибка: Необходимо указать версию в формате v1.0.25"; \
echo "Использование: make release VERSION=1.0.25"; \
exit 1; \
fi
@./scripts/release-interactive.sh $(VERSION)
release-interactive:
@./scripts/release-interactive.sh

133
scripts/release-interactive.sh Executable file
View File

@@ -0,0 +1,133 @@
#!/bin/bash
# Интерактивный скрипт для автоматизации релиза
# Использование: ./scripts/release-interactive.sh [version]
# Если версия не указана, скрипт запросит её интерактивно
set -e # Остановить выполнение при ошибке
# Функция для получения версии интерактивно
get_version_interactive() {
echo "🚀 Создание нового релиза"
echo ""
# Показываем текущую версию
CURRENT_VERSION=$(grep 'const version = "' main.go | sed 's/const version = "\([^"]*\)"/\1/')
echo "📋 Текущая версия: $CURRENT_VERSION"
echo ""
# Запрашиваем новую версию
read -p "Введите новую версию (формат X.Y.Z): " VERSION
# Проверяем, что версия не пустая
if [ -z "$VERSION" ]; then
echo "❌ Версия не может быть пустой"
exit 1
fi
# Проверяем формат версии
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Неверный формат версии. Используйте формат X.Y.Z (например, 1.0.25)"
exit 1
fi
# Подтверждение
echo ""
echo "📝 Подтверждение:"
echo " Текущая версия: $CURRENT_VERSION"
echo " Новая версия: $VERSION"
echo ""
read -r -p "Продолжить? (y/N): " CONFIRM
if [[ ! $CONFIRM =~ ^[Yy]$ ]]; then
echo "❌ Релиз отменен"
exit 0
fi
}
# Проверяем, передана ли версия как аргумент
if [ $# -eq 0 ]; then
# Версия не указана, запрашиваем интерактивно
get_version_interactive
else
# Версия указана как аргумент
VERSION=$1
# Проверка формата версии
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Ошибка: Неверный формат версии. Используйте формат X.Y.Z (например, 1.0.25)"
exit 1
fi
fi
echo "🚀 Начинаем релиз версии v$VERSION..."
# Проверяем, что мы в git репозитории
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Ошибка: Не найден git репозиторий"
exit 1
fi
# Проверяем, что нет незакоммиченных изменений
# if ! git diff-index --quiet HEAD --; then
# echo "Ошибка: Есть незакоммиченные изменения. Сначала закоммитьте их."
# exit 1
# fi
# Обновляем версию в main.go
echo "📝 Обновляем версию в main.go..."
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/const version = \"[^\"]*\"/const version = \"$VERSION\"/" main.go
else
# Linux
sed -i "s/const version = \"[^\"]*\"/const version = \"$VERSION\"/" main.go
fi
# Проверяем, что изменение применилось
if ! grep -q "const version = \"$VERSION\"" main.go; then
echo "Ошибка: Не удалось обновить версию в main.go"
exit 1
fi
echo "✅ Версия обновлена в main.go"
# Обновляем версию в makefile
echo "📝 Обновляем версию в makefile..."
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/^VERSION=.*/VERSION=$VERSION/" makefile
else
# Linux
sed -i "s/^VERSION=.*/VERSION=$VERSION/" makefile
fi
# Проверяем, что изменение применилось
if ! grep -q "^VERSION=$VERSION" makefile; then
echo "Ошибка: Не удалось обновить версию в makefile"
exit 1
fi
echo "✅ Версия обновлена в makefile"
# Выполняем git команды
echo "📦 Добавляем изменения в git..."
git add .
echo "💾 Создаем коммит..."
git commit -m "Release v$VERSION"
echo "🏷️ Создаем тег..."
git tag -a "v$VERSION" -m "Release v$VERSION"
echo "🚀 Отправляем изменения и теги..."
git push
git push --tags
echo "🎉 Релиз v$VERSION успешно завершен!"
echo "📋 Выполненные действия:"
echo " - Обновлена версия в main.go"
echo " - Обновлена версия в makefile"
echo " - Создан коммит с сообщением 'Release v$VERSION'"
echo " - Создан тег v$VERSION"
echo " - Изменения отправлены в удаленный репозиторий"