Update build (knowingly going to user repo)
This commit is contained in:
@@ -1,127 +1,57 @@
|
|||||||
# .gitea/workflows/release.yml
|
name: release-tag
|
||||||
|
|
||||||
name: Build and Release Docker Image
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main # Or your default branch, e.g., master
|
- master
|
||||||
tags:
|
|
||||||
- 'v*.*.*' # Trigger on version tags like v1.0.0, v1.2.3-alpha
|
|
||||||
pull_request: # Optional: build on PRs for testing, no push or release
|
|
||||||
branches:
|
|
||||||
- main # Or your default branch
|
|
||||||
|
|
||||||
env:
|
|
||||||
# Assumes your Gitea instance FQDN is correctly identified by gitea.instance
|
|
||||||
# e.g., gitea.example.com
|
|
||||||
# The image will be named: <gitea_instance_url>/<owner>/<repo_name>:<tag>
|
|
||||||
REGISTRY_HOST: ${{ gitea.instance }}
|
|
||||||
IMAGE_NAME_PATH: ${{ gitea.owner }}/${{ gitea.repository_name }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push-image:
|
release-image:
|
||||||
runs-on: ubuntu-latest # Ensure your Gitea runner supports Docker
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
DOCKER_LATEST: nightly
|
||||||
|
CONTAINER_NAME: drb-client-discord-bot
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up QEMU
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
- name: Login to Gitea Container Registry
|
- name: Set up Docker BuildX
|
||||||
# Ensure GITEA_TOKEN secret is created in your repository settings.
|
uses: docker/setup-buildx-action@v3
|
||||||
# It needs permissions to write to packages (container registry).
|
with: # replace it with your local IP
|
||||||
# gitea.actor is the user who triggered the workflow.
|
config-inline: |
|
||||||
|
[registry."git.vpn.cusano.net"]
|
||||||
|
http = false
|
||||||
|
insecure = false
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY_HOST }}
|
registry: git.vpn.cusano.net # replace it with your local IP
|
||||||
username: ${{ gitea.actor }}
|
username: ${{ secrets.GIT_REPO_USERNAME }}
|
||||||
password: ${{ secrets.GITEA_TOKEN }}
|
password: ${{ secrets.GIT_REPO_PASSWORD }}
|
||||||
|
|
||||||
- name: Extract Docker metadata
|
- name: Get Meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
run: |
|
||||||
|
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||||
|
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Validate build configuration
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
images: ${{ env.REGISTRY_HOST }}/${{ env.IMAGE_NAME_PATH }}
|
call: check
|
||||||
tags: |
|
|
||||||
# For pushes to the default branch (e.g., main)
|
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
|
||||||
type=sha,prefix=,format=short,enable={{is_default_branch}} # e.g., sha-1234567
|
|
||||||
|
|
||||||
# For version tags like v1.2.3
|
- name: Build and push
|
||||||
# Produces: 1.2.3 from tag v1.2.3
|
uses: docker/build-push-action@v6
|
||||||
type=semver,pattern={{version}}
|
|
||||||
# Produces: 1.2 from tag v1.2.3
|
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
|
||||||
# Produces: 1 from tag v1.2.3
|
|
||||||
type=semver,pattern={{major}}
|
|
||||||
# Also tag vX.Y.Z as 'latest'
|
|
||||||
type=raw,value=latest,enable=${{ startsWith(gitea.ref, 'refs/tags/v') }}
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
# Only push if it's not a pull request event
|
platforms: |
|
||||||
push: ${{ gitea.event_name != 'pull_request' }}
|
linux/arm64
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
push: true
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
tags: | # replace it with your local IP and tags
|
||||||
# Enable build cache using Gitea Actions cache
|
git.vpn.cusano.net/${{ vars.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}/${{ env.CONTAINER_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
|
||||||
cache-from: type=gha
|
git.vpn.cusano.net/${{ vars.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}/${{ env.CONTAINER_NAME }}:${{ env.DOCKER_LATEST }}
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
|
|
||||||
create-gitea-release:
|
|
||||||
needs: build-and-push-image
|
|
||||||
# Only run this job if the trigger was a tag push matching 'v*.*.*'
|
|
||||||
if: startsWith(gitea.ref, 'refs/tags/v')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Get tag name
|
|
||||||
id: get_tag
|
|
||||||
# GITEA_REF is like 'refs/tags/v1.2.3', this extracts 'v1.2.3'
|
|
||||||
run: echo "TAG_NAME=${GITEA_REF#refs/tags/}" >> $GITEA_ENV
|
|
||||||
|
|
||||||
- name: Create Gitea Release
|
|
||||||
env:
|
|
||||||
# GITEA_TOKEN needs permissions to create releases (e.g., repository:write).
|
|
||||||
# It can be the same token used for registry login if it has sufficient scope.
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
TAG_NAME: ${{ env.TAG_NAME }} # From previous step
|
|
||||||
OWNER: ${{ gitea.owner }}
|
|
||||||
REPO: ${{ gitea.repository_name }}
|
|
||||||
# gitea.server_url is like https://gitea.example.com
|
|
||||||
GITEA_API_URL: ${{ gitea.server_url }}/api/v1
|
|
||||||
run: |
|
|
||||||
echo "Creating Gitea release for tag: $TAG_NAME"
|
|
||||||
RELEASE_API_ENDPOINT="$GITEA_API_URL/repos/$OWNER/$REPO/releases"
|
|
||||||
|
|
||||||
# You can customize the release body, e.g., by fetching changelog notes
|
|
||||||
RELEASE_BODY="Official release for version $TAG_NAME."
|
|
||||||
|
|
||||||
# Create the release using Gitea API
|
|
||||||
response=$(curl --request POST \
|
|
||||||
--url "$RELEASE_API_ENDPOINT" \
|
|
||||||
--header "Authorization: token $GITEA_TOKEN" \
|
|
||||||
--header "Content-Type: application/json" \
|
|
||||||
--data @- <<EOF
|
|
||||||
{
|
|
||||||
"tag_name": "$TAG_NAME",
|
|
||||||
"name": "$TAG_NAME",
|
|
||||||
"body": "$RELEASE_BODY",
|
|
||||||
"draft": false,
|
|
||||||
"prerelease": false
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
echo "Gitea API Response: $response"
|
|
||||||
|
|
||||||
# Basic check for success (Gitea API returns an 'id' on successful release creation)
|
|
||||||
if echo "$response" | grep -q '"id":'; then
|
|
||||||
echo "✅ Gitea Release '$TAG_NAME' created successfully."
|
|
||||||
else
|
|
||||||
echo "❌ Error creating Gitea Release. Response: $response"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
Reference in New Issue
Block a user