This commit is contained in:
281
.gitea/workflows/release_build.yml
Normal file
281
.gitea/workflows/release_build.yml
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
name: Build, Push, Publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '28 5 * * *'
|
||||||
|
# workflow_run support in Gitea can be tricky, keeping it but might need adjustment
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["Sync Repo"]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: Build & Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: 📥 Checkout code with full history and tags
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Check if any tags exist
|
||||||
|
id: check_tags_exist
|
||||||
|
run: |
|
||||||
|
git fetch --tags
|
||||||
|
TAG_COUNT=$(git tag | wc -l)
|
||||||
|
if [ "$TAG_COUNT" -eq 0 ]; then
|
||||||
|
echo "has_tags=false" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "latest_tag=v0.0.0" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "has_tags=true" >> "$GITHUB_OUTPUT"
|
||||||
|
LATEST_TAG=$(git describe --tags --abbrev=0)
|
||||||
|
echo "latest_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Check if meaningful commits exist since latest tag
|
||||||
|
id: check_commits
|
||||||
|
run: |
|
||||||
|
if [ "${{ steps.check_tags_exist.outputs.has_tags }}" = "false" ]; then
|
||||||
|
# No tags exist, so we should create first release
|
||||||
|
echo "commit_count=1" >> "$GITHUB_OUTPUT"
|
||||||
|
CHANGED_FILES=$(git ls-files | grep -v '^manifest.json$' || true)
|
||||||
|
if [ -n "$CHANGED_FILES" ]; then
|
||||||
|
echo "changed_files<<EOF" >> "$GITHUB_OUTPUT"
|
||||||
|
printf '%s\n' "$CHANGED_FILES" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "changed_files=Initial release" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
LATEST_TAG="${{ steps.check_tags_exist.outputs.latest_tag }}"
|
||||||
|
CHANGED_FILES="$(git diff --name-only "${LATEST_TAG}..HEAD" | grep -v '^manifest.json$' || true)"
|
||||||
|
if [ -n "$CHANGED_FILES" ]; then
|
||||||
|
echo "commit_count=1" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "changed_files<<EOF" >> "$GITHUB_OUTPUT"
|
||||||
|
printf '%s\n' "$CHANGED_FILES" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "commit_count=0" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Get latest release tag (from Gitea API)
|
||||||
|
id: get_latest_release
|
||||||
|
run: |
|
||||||
|
# Using Gitea API
|
||||||
|
LATEST_RELEASE_TAG=$(curl -sL -H "Accept: application/json" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
"${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/latest" | jq -r .tag_name)
|
||||||
|
|
||||||
|
if [ -z "$LATEST_RELEASE_TAG" ] || [ "$LATEST_RELEASE_TAG" = "null" ]; then
|
||||||
|
LATEST_RELEASE_TAG="v1.0.0"
|
||||||
|
fi
|
||||||
|
echo "latest_release_tag=$LATEST_RELEASE_TAG" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "latest_release_version=${LATEST_RELEASE_TAG#v}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
# -------------------------------
|
||||||
|
# Sync manifest.json to last release version if behind (only when no meaningful commits)
|
||||||
|
# -------------------------------
|
||||||
|
- name: 🛠 Ensure manifest.json matches latest release version
|
||||||
|
if: steps.check_commits.outputs.commit_count == '0'
|
||||||
|
run: |
|
||||||
|
if [ -f manifest.json ]; then
|
||||||
|
MANIFEST_VERSION=$(jq -r '.version // empty' manifest.json)
|
||||||
|
else
|
||||||
|
MANIFEST_VERSION=""
|
||||||
|
fi
|
||||||
|
LATEST_RELEASE_VERSION="${{ steps.get_latest_release.outputs.latest_release_version }}"
|
||||||
|
PYTHON_CODE="from packaging import version; \
|
||||||
|
print(version.parse('$LATEST_RELEASE_VERSION') > version.parse('$MANIFEST_VERSION') if '$MANIFEST_VERSION' else True)"
|
||||||
|
# Python3 is available in catthehacker/ubuntu:act-latest
|
||||||
|
NEED_UPDATE=$(python3 -c "$PYTHON_CODE")
|
||||||
|
if [ "$NEED_UPDATE" = "True" ]; then
|
||||||
|
echo "Updating manifest.json to version $LATEST_RELEASE_VERSION (sync with release)"
|
||||||
|
jq --arg v "$LATEST_RELEASE_VERSION" '.version = $v' manifest.json > tmp.json && mv tmp.json manifest.json
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@git.icc.gg"
|
||||||
|
git add manifest.json
|
||||||
|
git commit -m "Sync manifest.json to release $LATEST_RELEASE_VERSION [🔄]" || echo "Nothing to commit"
|
||||||
|
git push origin main || true
|
||||||
|
else
|
||||||
|
echo "Manifest.json is already up-to-date with the latest release."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# -------------------------------
|
||||||
|
# Continue normal workflow if commits exist
|
||||||
|
# -------------------------------
|
||||||
|
- name: 📃 Get list of changed files (Markdown bullet list)
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
id: changed_files
|
||||||
|
run: |
|
||||||
|
BULLET_LIST="$(printf '%s\n' "${{ steps.check_commits.outputs.changed_files }}" | sed 's/^/- /')"
|
||||||
|
echo "CHANGED<<EOF" >> "$GITHUB_OUTPUT"
|
||||||
|
printf '%s\n' "$BULLET_LIST" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||||
|
COUNT="$(printf '%s\n' "${{ steps.check_commits.outputs.changed_files }}" | wc -l)"
|
||||||
|
echo "COUNT=$COUNT" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Get manifest version
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
id: get_manifest_version
|
||||||
|
run: |
|
||||||
|
if [ -f manifest.json ]; then
|
||||||
|
MANIFEST_VERSION=$(jq -r '.version // empty' manifest.json)
|
||||||
|
if [ -z "$MANIFEST_VERSION" ] || [ "$MANIFEST_VERSION" = "null" ]; then
|
||||||
|
MANIFEST_VERSION="1.0.0"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
MANIFEST_VERSION="1.0.0"
|
||||||
|
fi
|
||||||
|
echo "manifest_version=$MANIFEST_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Pick base version
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
id: pick_base_version
|
||||||
|
run: |
|
||||||
|
LATEST_RELEASE="${{ steps.get_latest_release.outputs.latest_release_version }}"
|
||||||
|
MANIFEST="${{ steps.get_manifest_version.outputs.manifest_version }}"
|
||||||
|
BASE_VERSION=$(python3 -c "from packaging import version; \
|
||||||
|
print(str(max(version.parse('$LATEST_RELEASE'), version.parse('$MANIFEST'))))")
|
||||||
|
echo "base_version=$BASE_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: 🔢 Determine version
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
BASE_VERSION="${{ steps.pick_base_version.outputs.base_version }}"
|
||||||
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
|
||||||
|
COUNT="${{ steps.changed_files.outputs.COUNT }}"
|
||||||
|
if [ "$COUNT" -ge 5 ]; then
|
||||||
|
MAJOR=$((MAJOR + 1))
|
||||||
|
MINOR=0
|
||||||
|
PATCH=0
|
||||||
|
elif [ "$COUNT" -ge 3 ]; then
|
||||||
|
MINOR=$((MINOR + 1))
|
||||||
|
PATCH=0
|
||||||
|
else
|
||||||
|
PATCH=$((PATCH + 1))
|
||||||
|
fi
|
||||||
|
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
|
||||||
|
REPO_NAME="$(basename "$GITHUB_REPOSITORY")"
|
||||||
|
ZIP_NAME="${REPO_NAME}-${NEW_VERSION}.zip"
|
||||||
|
echo "VERSION=$NEW_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "ZIP_NAME=$ZIP_NAME" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "REPO_NAME=$REPO_NAME" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: 🛠 Update or create manifest.json
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
run: |
|
||||||
|
VERSION="${{ steps.version.outputs.VERSION }}"
|
||||||
|
AUTHOR="Ivan Carlos"
|
||||||
|
VERSION_FILE="manifest.json"
|
||||||
|
if [ -f "$VERSION_FILE" ]; then
|
||||||
|
jq --arg v "$VERSION" --arg a "$AUTHOR" \
|
||||||
|
'.version = $v | .author = $a' "$VERSION_FILE" > tmp.json && mv tmp.json "$VERSION_FILE"
|
||||||
|
else
|
||||||
|
echo "{ \"version\": \"$VERSION\", \"author\": \"$AUTHOR\" }" > "$VERSION_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: 💾 Commit and push updated manifest.json
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
run: |
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@git.icc.gg"
|
||||||
|
git add manifest.json
|
||||||
|
git commit -m "Update manifest version to ${{ steps.version.outputs.VERSION }} [▶️]" || echo "Nothing to commit"
|
||||||
|
git push origin main
|
||||||
|
|
||||||
|
- name: 📦 Create ZIP package (excluding certain files)
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
run: |
|
||||||
|
ZIP_NAME="${{ steps.version.outputs.ZIP_NAME }}"
|
||||||
|
zip -r "$ZIP_NAME" . -x ".git/*" ".github/*" "docker/*" ".dockerignore" "CNAME" "Dockerfile" "README.md" "LICENSE" ".gitea/*"
|
||||||
|
|
||||||
|
- name: 🚀 Create Gitea Release
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
id: create_release
|
||||||
|
run: |
|
||||||
|
TAG_NAME="v${{ steps.version.outputs.VERSION }}"
|
||||||
|
RELEASE_NAME="${{ steps.version.outputs.REPO_NAME }} v${{ steps.version.outputs.VERSION }}"
|
||||||
|
BODY="### Changelog\nFiles changed in this release:\n${{ steps.changed_files.outputs.CHANGED }}"
|
||||||
|
|
||||||
|
# Create Release
|
||||||
|
RESPONSE=$(curl -s -X POST "${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d @- <<EOF
|
||||||
|
{
|
||||||
|
"tag_name": "$TAG_NAME",
|
||||||
|
"name": "$RELEASE_NAME",
|
||||||
|
"body": $(jq -n --arg body "$BODY" '$body'),
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
RELEASE_ID=$(echo "$RESPONSE" | jq -r .id)
|
||||||
|
echo "RELEASE_ID=$RELEASE_ID" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
if [ "$RELEASE_ID" == "null" ]; then
|
||||||
|
echo "Failed to create release: $RESPONSE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: 📤 Upload Release Asset
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
run: |
|
||||||
|
RELEASE_ID="${{ steps.create_release.outputs.RELEASE_ID }}"
|
||||||
|
ZIP_NAME="${{ steps.version.outputs.ZIP_NAME }}"
|
||||||
|
FILE_PATH="./$ZIP_NAME"
|
||||||
|
|
||||||
|
curl -s -X POST "${{ gitea.api_url }}/repos/${{ gitea.repository }}/releases/$RELEASE_ID/assets" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Content-Type: application/zip" \
|
||||||
|
--data-binary @"$FILE_PATH" \
|
||||||
|
-o /dev/null
|
||||||
|
|
||||||
|
# ----- Docker steps -----
|
||||||
|
- name: 🔍 Check if Dockerfile exists
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0'
|
||||||
|
id: dockerfile_check
|
||||||
|
run: |
|
||||||
|
if [ -f Dockerfile ]; then
|
||||||
|
echo "exists=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "exists=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: 🔐 Login to Gitea Container Registry
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0' && steps.dockerfile_check.outputs.exists == 'true'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.icc.gg
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.CR_PAT }}
|
||||||
|
|
||||||
|
- name: 🛠 Set up Docker Buildx
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0' && steps.dockerfile_check.outputs.exists == 'true'
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: 🐳 Build and Push Docker image
|
||||||
|
if: steps.check_commits.outputs.commit_count != '0' && steps.dockerfile_check.outputs.exists == 'true'
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
git.icc.gg/${{ gitea.repository }}:latest
|
||||||
|
git.icc.gg/${{ gitea.repository }}:${{ steps.version.outputs.VERSION }}
|
||||||
45
.gitea/workflows/sync_repo.yml
Normal file
45
.gitea/workflows/sync_repo.yml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
name: Sync Repo
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '34 3 * * *' # 03:34 UTC == 00:34 BRT
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
download-aws-sdk:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
actions: write # needed to dispatch another workflow
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download AWS SDK PHAR
|
||||||
|
run: |
|
||||||
|
mkdir -p vendor
|
||||||
|
wget https://github.com/aws/aws-sdk-php/releases/latest/download/aws.phar -O vendor/aws.phar
|
||||||
|
|
||||||
|
- name: Commit and push changes
|
||||||
|
id: commit_step
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory '*'
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@git.icc.gg"
|
||||||
|
git add vendor/aws.phar
|
||||||
|
|
||||||
|
# If there are changes, commit & push; set output flag accordingly
|
||||||
|
if git diff --quiet && git diff --staged --quiet; then
|
||||||
|
echo "No changes to commit"
|
||||||
|
echo "changes_committed=false" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
git commit -m "Update AWS SDK PHAR [▶️]"
|
||||||
|
git push origin HEAD:main
|
||||||
|
echo "changes_committed=true" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
96
.gitea/workflows/update_readme.yml
Normal file
96
.gitea/workflows/update_readme.yml
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
name: Update README
|
||||||
|
|
||||||
|
# Allow Gitea Actions to commit and push changes
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 4 * * *' # Every day at 4 AM UTC
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update-readme:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Adjusted for Gitea profile convention (usually owner/.profile or owner/.gitea)
|
||||||
|
# Please verify if 'ivancarlos/.profile' exists or adjust to your profile repository.
|
||||||
|
SOURCE_REPO: ivancarlos/.profile
|
||||||
|
SOURCE_BRANCH: main
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout current repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Checkout source README template
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: ${{ env.SOURCE_REPO }}
|
||||||
|
ref: ${{ env.SOURCE_BRANCH }}
|
||||||
|
path: source_readme
|
||||||
|
|
||||||
|
- name: Update README.md (buttons and footer)
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
REPO_NAME="${GITHUB_REPOSITORY##*/}"
|
||||||
|
|
||||||
|
# --- Extract buttons block from source ---
|
||||||
|
# Checking if source file exists, if not, skip or fail.
|
||||||
|
if [ ! -f source_readme/README.md ]; then
|
||||||
|
echo "Source README not found in ${SOURCE_REPO}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
BUTTONS=$(awk '/<!-- buttons -->/{flag=1;next}/<!-- endbuttons -->/{flag=0}flag' source_readme/README.md)
|
||||||
|
BUTTONS_UPDATED=$(echo "$BUTTONS" | sed "s/\.github/${REPO_NAME}/g")
|
||||||
|
|
||||||
|
# --- Extract footer block from source (everything from <!-- footer --> onward) ---
|
||||||
|
FOOTER=$(awk '/<!-- footer -->/{flag=1}flag' source_readme/README.md)
|
||||||
|
|
||||||
|
# --- Replace buttons section in README.md ---
|
||||||
|
UPDATED=$(awk -v buttons="$BUTTONS_UPDATED" '
|
||||||
|
BEGIN { skip=0 }
|
||||||
|
/<!-- buttons -->/ {
|
||||||
|
print
|
||||||
|
print buttons
|
||||||
|
skip=1
|
||||||
|
next
|
||||||
|
}
|
||||||
|
/<!-- endbuttons -->/ && skip {
|
||||||
|
print
|
||||||
|
print buttons
|
||||||
|
skip=0
|
||||||
|
next
|
||||||
|
}
|
||||||
|
!skip { print }
|
||||||
|
' README.md)
|
||||||
|
|
||||||
|
# --- Replace everything after <!-- footer --> with FOOTER ---
|
||||||
|
echo "$UPDATED" | awk -v footer="$FOOTER" '
|
||||||
|
/<!-- footer -->/ {
|
||||||
|
print footer
|
||||||
|
found=1
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
{ print }
|
||||||
|
' > README.tmp && mv README.tmp README.md
|
||||||
|
|
||||||
|
- name: Remove source_readme from git index
|
||||||
|
run: rm -rf source_readme || true
|
||||||
|
|
||||||
|
- name: Commit and push changes
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory '*'
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@git.icc.gg"
|
||||||
|
|
||||||
|
if [ -n "$(git status --porcelain README.md)" ]; then
|
||||||
|
git add README.md
|
||||||
|
git commit -m "Sync README from template [▶️]"
|
||||||
|
git push origin HEAD:${{ github.ref_name }}
|
||||||
|
else
|
||||||
|
echo "No changes to README.md"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user