Skip to content
Closed

pull #119

Show file tree
Hide file tree
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
106 changes: 106 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Create Release

# This workflow automatically creates GitHub releases when the version file is updated
# It extracts changelog information from README.md (preferred) or CHANGELOG.md (fallback)
# Version information is read from the 'version' file in the repository root

on:
push:
branches: [ main ]
paths:
- 'version'

permissions:
contents: write
pull-requests: write
issues: write

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Check if version file changed
id: check
run: |
if git diff HEAD~1 HEAD --name-only | grep -q "^version$"; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version file has changed"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version file has not changed"
fi

- name: Read version
id: version
if: steps.check.outputs.changed == 'true'
run: |
VERSION=$(cat version | tr -d '\n' | sed 's/^v//')
TAG_VERSION=$(cat version | tr -d '\n')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"
echo "Tag version: $TAG_VERSION"

- name: Generate changelog
id: changelog
if: steps.check.outputs.changed == 'true'
run: |
VERSION="${{ steps.version.outputs.version }}"

# Generate changelog using cat with heredoc
CHANGELOG=$(cat << 'EOL'
## 🚀 HoyoLab Auto v${VERSION}

Automatically generated release from version file update.

### Changes
- Updated to version ${VERSION}
- See commit history for detailed changes

**Full Changelog**: [View all changes](https://github.com/TheInfamousToTo/hoyolab-auto/commits/v${VERSION})
EOL
)

# Substitute the VERSION variable
CHANGELOG=$(echo "$CHANGELOG" | sed "s/\${VERSION}/$VERSION/g")

# Debug output
echo "Generated changelog preview:"
echo "$CHANGELOG" | head -10

# Save changelog to output (GitHub Actions multiline string)
{
echo "changelog<<EOF"
echo "$CHANGELOG"
echo "EOF"
} >> $GITHUB_OUTPUT

- name: Check if tag exists
id: check-tag
if: steps.check.outputs.changed == 'true'
run: |
TAG_VERSION="${{ steps.version.outputs.tag_version }}"
if git tag -l | grep -q "^$TAG_VERSION$"; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag $TAG_VERSION already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag $TAG_VERSION does not exist"
fi

- name: Create GitHub Release
if: steps.check.outputs.changed == 'true' && steps.check-tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.tag_version }}
name: "HoyoLab Auto ${{ steps.version.outputs.tag_version }}"
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66 changes: 66 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Docker Build and Push

on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
workflow_run:
workflows: ["Create Release"]
types:
- completed

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Read version from file
id: version
run: |
VERSION=$(cat version | tr -d '\n' | sed 's/^v//')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Debug secrets
if: github.event_name != 'pull_request'
run: |
if [ -z "$DOCKERHUB_USERNAME" ]; then echo "❌ DOCKERHUB_USERNAME is empty"; fi
if [ -z "$DOCKERHUB_TOKEN" ]; then echo "❌ DOCKERHUB_TOKEN is empty"; fi
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: theinfamoustoto/hoyolab-auto
tags: |
type=raw,value=${{ steps.version.outputs.version }}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
74 changes: 50 additions & 24 deletions .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,53 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up QEMU (for multi-arch)
uses: docker/setup-qemu-action@v3

- name: Set up Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR (PAT)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/${{ secrets.GHCR_USERNAME }}/hoyolab-auto:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Checkout repository
uses: actions/checkout@v4

- name: Read version from file
id: version
run: |
VERSION=$(cat version | tr -d '\n' | sed 's/^v//')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"

- name: Debug version
run: |
echo "Version from file: '${{ steps.version.outputs.version }}'"
echo "Length: ${#VERSION}"
if [ -z "${{ steps.version.outputs.version }}" ]; then
echo "❌ Version is empty!"
else
echo "✅ Version is: ${{ steps.version.outputs.version }}"
fi

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/theinfamoustoto/hoyolab-auto
tags: |
type=raw,value=${{ steps.version.outputs.version }}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ services:
- ./data:/app/data
- ./logs:/app/logs
environment:
TZ: Asia/Shanghai
TZ: Asia/Bahrain