Skip to content

Commit

Permalink
Merge branch 'main' into upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Silentely authored Nov 1, 2024
2 parents 94b839f + c702800 commit ab95c95
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .github/delete-merged-branch-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exclude:
- upstream
- feature-*
delete_closed_pr: true
7 changes: 7 additions & 0 deletions .github/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "1"
rules:
- base: upstream
upstream: damonto:main
mergeMethod: merge
mergeUnstable: false

15 changes: 15 additions & 0 deletions .github/workflows/clean-workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Auto cleaning of workflow logs'

on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:

jobs:
del_workflow:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: GitRML/delete-workflow-runs@main
with:
retain_days: '7'
39 changes: 25 additions & 14 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: Docker Image

on:
workflow_dispatch:
inputs:
tag:
description: 'Tag name'
required: true
push:
tags: [v*]
pull_request:
branches: [main]

permissions:
contents: read
Expand All @@ -21,13 +23,14 @@ jobs:
platform:
- linux/amd64
- linux/arm64
- linux/arm/v7

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
ref: ${{ github.event.inputs.tag || github.ref }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -50,18 +53,21 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Convert repository owner to lowercase
id: lowercase-owner
run: echo "lowercase_owner=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/estkme-cloud
ghcr.io/${{ env.lowercase_owner }}/estkme-cloud
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=tag
- name: Build and push by digest
Expand All @@ -72,11 +78,11 @@ jobs:
platforms: ${{ matrix.platform }}
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=true
VERSION=${{ steps.meta.outputs.version }}
VERSION=${{ github.event.inputs.tag || steps.meta.outputs.version }}
provenance: false
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
outputs: type=image,"name=ghcr.io/${{ github.repository_owner }}/estkme-cloud,docker.io/${{ secrets.DOCKERHUB_USERNAME }}/estkme-cloud",push-by-digest=true,name-canonical=true,push=${{ startsWith(github.ref, 'refs/tags/v') }}
outputs: type=image,"name=ghcr.io/${{ env.lowercase_owner }}/estkme-cloud,docker.io/${{ secrets.DOCKERHUB_USERNAME }}/estkme-cloud",push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max

Expand All @@ -101,7 +107,7 @@ jobs:

merge:
name: Merge and Push image manifest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event.inputs.tag }}
runs-on: ubuntu-latest
needs:
- build
Expand All @@ -116,19 +122,22 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set repository owner
id: set_repo_owner
run: echo "REPO_OWNER_1=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/estkme-cloud
ghcr.io/${{ env.REPO_OWNER_1 }}/estkme-cloud
docker.io/${{ secrets.DOCKERHUB_USERNAME }}/estkme-cloud
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=tag
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: index
Expand All @@ -152,12 +161,13 @@ jobs:
set -x
annotations=$(jq -cr '.annotations | map((split("=")[0] + "=\"" + split("=")[1] + "\"") | "--annotation " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
tags=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
eval "docker buildx imagetools create $annotations $tags $(printf 'ghcr.io/${{ github.repository_owner }}/estkme-cloud@sha256:%s ' *)"
digests=$(ls -1 | tr '\n' ' ' | sed 's#^#ghcr.io/${{ env.REPO_OWNER_1 }}/estkme-cloud@sha256:#' | tr '[:upper:]' '[:lower:]')
eval "docker buildx imagetools create $annotations $tags $digests"
- name: Inspect image
run: |
docker buildx imagetools inspect docker.io/${{ secrets.DOCKERHUB_USERNAME }}/estkme-cloud:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ghcr.io/${{ github.repository_owner }}/estkme-cloud:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ghcr.io/${{ env.REPO_OWNER_1 }}/estkme-cloud:${{ steps.meta.outputs.version }}
cleanup:
name: Cleanup
Expand All @@ -169,3 +179,4 @@ jobs:
uses: dataaxiom/ghcr-cleanup-action@v1
with:
token: ${{ github.token }}
continue-on-error: true
40 changes: 40 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Upstream Sync

permissions:
contents: write

on:
schedule:
- cron: "0 0 * * *" # every day
workflow_dispatch:

jobs:
sync_latest_from_upstream:
name: Sync latest commits from upstream repo
runs-on: ubuntu-latest
if: ${{ github.event.repository.fork }}

steps:
# Step 1: run a standard checkout action
- name: Checkout target repo
uses: actions/checkout@v4

# Step 2: run the sync action
- name: Sync upstream changes
id: sync
uses: aormsby/[email protected]
with:
upstream_sync_repo: https://github.com/damonto/estkme-cloud
upstream_sync_branch: main
target_sync_branch: upstream
target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set

# Set test_mode true to run tests instead of the true action!!
test_mode: false

- name: Sync check
if: failure()
run: |
echo "[Error] 由于上游仓库的 workflow 文件变更,导致 GitHub 自动暂停了本次自动更新,你需要手动 Sync Fork 一次,详细教程请查看:https://github.com/Yidadaa/ChatGPT-Next-Web/blob/main/README_CN.md#%E6%89%93%E5%BC%80%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0"
echo "[Error] Due to a change in the workflow file of the upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork. Please refer to the detailed tutorial for instructions: https://github.com/Yidadaa/ChatGPT-Next-Web#enable-automatic-updates"
exit 1
40 changes: 40 additions & 0 deletions .github/workflows/tag-and-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tag and Build on PR Merge

on:
pull_request:
types: [closed]

jobs:
tag-and-build:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true

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

- name: Generate tag name
id: generate_tag
run: |
TAG_NAME="v$(TZ=UTC-8 date +'%Y%m%d%H%M')"
COUNT=1
while git rev-parse $TAG_NAME >/dev/null 2>&1; do
TAG_NAME="${TAG_NAME}-${COUNT}"
COUNT=$((COUNT + 1))
done
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_ENV
- name: Create tag
run: |
git tag ${{ env.TAG_NAME }}
git push origin ${{ env.TAG_NAME }}
- name: Trigger build workflow
uses: benc-uk/workflow-dispatch@v1
with:
workflow: docker.yml
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.ref }}
inputs: '{"tag": "${{ env.TAG_NAME }}"}'

0 comments on commit ab95c95

Please sign in to comment.