mirror of
https://github.com/khairul169/garage-webui.git
synced 2025-10-14 23:09:32 +07:00
feat: add GitHub Actions workflow for automated release process
This commit is contained in:
parent
7274162a31
commit
e2b103f80a
40
.github/workflows/README.md
vendored
Normal file
40
.github/workflows/README.md
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
# GitHub Release Workflow
|
||||
|
||||
This document describes the GitHub Actions workflow for releasing the Garage UI project.
|
||||
|
||||
## How to Create a Release
|
||||
|
||||
1. Create a new tag following semantic versioning and push it to GitHub:
|
||||
```bash
|
||||
git tag v1.0.0
|
||||
git push origin v1.0.0
|
||||
```
|
||||
|
||||
2. The workflow will automatically create a GitHub release and build everything
|
||||
|
||||
## What the Workflow Does
|
||||
|
||||
When a new tag is pushed, the workflow will:
|
||||
|
||||
1. Extract the version from the tag (e.g., v1.0.0 becomes 1.0.0)
|
||||
2. Build the Docker image and push it to GitHub Container Registry with appropriate version tags
|
||||
3. Build binaries for various platforms (Linux with architectures: 386, amd64, arm, arm64) using the tag version
|
||||
4. Create a GitHub release and attach the binaries as assets
|
||||
|
||||
## Docker Images
|
||||
|
||||
The Docker images will be available at:
|
||||
- `ghcr.io/adekabang/garage-ui:latest`
|
||||
- `ghcr.io/adekabang/garage-ui:X.Y.Z` (version tag)
|
||||
- `ghcr.io/adekabang/garage-ui:X.Y` (major.minor tag)
|
||||
|
||||
## Binaries
|
||||
|
||||
The binaries will be attached to the GitHub release and can be downloaded directly from the release page.
|
||||
|
||||
## Configuration
|
||||
|
||||
If you want to also push Docker images to Docker Hub, uncomment and configure the Docker Hub login section in the workflow file and add the following secrets to your repository:
|
||||
|
||||
- `DOCKERHUB_USERNAME`: Your Docker Hub username
|
||||
- `DOCKERHUB_TOKEN`: Your Docker Hub access token
|
156
.github/workflows/release.yml
vendored
Normal file
156
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
DOCKER_HUB_REGISTRY: adekabang/garage-webui
|
||||
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
name: Build and push Docker image
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to the GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Optional: Log in to Docker Hub if you want to push there too
|
||||
# Uncomment and configure secrets in your GitHub repository settings
|
||||
# - name: Log in to Docker Hub
|
||||
# uses: docker/login-action@v3
|
||||
# with:
|
||||
# username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
# password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
#
|
||||
# - name: Add Docker Hub as additional image target
|
||||
# if: ${{ success() && secrets.DOCKERHUB_USERNAME != '' }}
|
||||
# run: |
|
||||
# docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} ${{ env.DOCKER_HUB_REGISTRY }}:${{ steps.get_version.outputs.VERSION }}
|
||||
# docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} ${{ env.DOCKER_HUB_REGISTRY }}:latest
|
||||
# docker push ${{ env.DOCKER_HUB_REGISTRY }}:${{ steps.get_version.outputs.VERSION }}
|
||||
# docker push ${{ env.DOCKER_HUB_REGISTRY }}:latest
|
||||
|
||||
- name: Get version from tag
|
||||
id: get_version
|
||||
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=raw,value=${{ steps.get_version.outputs.VERSION }}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=raw,value=latest
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
VERSION=${{ steps.get_version.outputs.VERSION }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
build-binaries:
|
||||
name: Build binaries
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.21'
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Set up PNPM
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 8
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Get version from tag
|
||||
id: get_version
|
||||
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create version.txt file with tag version
|
||||
run: echo "${{ steps.get_version.outputs.VERSION }}" > version.txt
|
||||
|
||||
- name: Create custom build script for tag-based versioning
|
||||
run: |
|
||||
cat > misc/tag-build.sh << 'EOF'
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
BINARY=garage-webui
|
||||
VERSION=$(cat version.txt)
|
||||
PLATFORMS="linux"
|
||||
ARCHITECTURES="386 amd64 arm arm64"
|
||||
|
||||
echo "Building version $VERSION"
|
||||
|
||||
pnpm run build
|
||||
cd backend && rm -rf dist && mkdir -p dist && rm -rf ./ui/dist && cp -r ../dist ./ui/dist
|
||||
|
||||
for PLATFORM in $PLATFORMS; do
|
||||
for ARCH in $ARCHITECTURES; do
|
||||
echo "Building $PLATFORM-$ARCH"
|
||||
|
||||
GOOS=$PLATFORM GOARCH=$ARCH go build -o "dist/$BINARY-v$VERSION-$PLATFORM-$ARCH" -tags="prod" main.go
|
||||
done
|
||||
done
|
||||
EOF
|
||||
|
||||
chmod +x misc/tag-build.sh
|
||||
|
||||
- name: Build binaries
|
||||
run: |
|
||||
./misc/tag-build.sh
|
||||
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
name: Release ${{ steps.get_version.outputs.VERSION }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
files: |
|
||||
backend/dist/garage-webui-*
|
||||
generate_release_notes: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
Loading…
x
Reference in New Issue
Block a user