Files
discord-emojis/.github/workflows/build.yaml
renovate[bot] df488e5500 ⬆️ Upgrade astral-sh/setup-uv action to v7 (#17)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-10-08 15:33:57 +02:00

101 lines
3.3 KiB
YAML

name: Emojis Auto Update
on:
schedule:
- cron: "0 0 * * 1,4"
workflow_dispatch:
concurrency:
group: emojis-autoupdate
jobs:
emojis-autoupdate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- uses: fregante/setup-git-user@v2
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
- name: Sync UV
run: uv sync
- name: Create or Checkout Branch
id: branch
run: |
# Create a new branch name with timestamp
NEW_BRANCH_NAME="emojis-autoupdate-$(date +%s)"
# Check for existing branches
git fetch origin
EXISTING_BRANCH=$(git branch -r | grep "origin/emojis-autoupdate-" || true)
if [ -z "$EXISTING_BRANCH" ]; then
# No existing branch, create a new one
echo "Creating new branch: $NEW_BRANCH_NAME"
git checkout -b $NEW_BRANCH_NAME
BRANCH_NAME=$NEW_BRANCH_NAME
else
# Found existing branch, extract name without "origin/"
BRANCH_NAME=$(echo $EXISTING_BRANCH | sed 's|origin/||' | tr -d '[:space:]')
echo "Found existing branch: $BRANCH_NAME"
# Create a local tracking branch
git checkout -b $BRANCH_NAME --track origin/$BRANCH_NAME || git checkout -b $BRANCH_NAME
# If that fails, fall back to new branch
if [ $? -ne 0 ]; then
echo "Failed to checkout existing branch, creating new: $NEW_BRANCH_NAME"
git checkout -b $NEW_BRANCH_NAME
BRANCH_NAME=$NEW_BRANCH_NAME
fi
fi
echo "Using branch: $BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
- name: Run Update Script
id: run_script
run: |
set +e
uv run src
CODE=$?
set -e
if [ $CODE -eq 0 ]; then
echo "Changes detected"
echo "changes_detected=true" >> $GITHUB_ENV
elif [ $CODE -eq 3 ]; then
echo "No changes detected"
echo "changes_detected=false" >> $GITHUB_ENV
# Transform it to 0 to avoid failing the workflow
echo "exit_code=0" >> $GITHUB_ENV
exit 0
else
echo "Script failed with exit code $EXIT_CODE"
echo "exit_code=$CODE" >> $GITHUB_ENV
exit $CODE
fi
- name: Commit and Push Changes
if: env.changes_detected == 'true'
run: |
git add build/*
git commit -m "Emojis autoupdate"
git push --force origin ${{ env.branch_name }}
- name: Open Pull Request
if: env.changes_detected == 'true'
# use the gh cli to create a pull request, first check if a pr already exists for the branch
run: |
EXISTING_PR=$(gh pr list --search "is:open label:emojis" --json headRefName,number,author -q '.[0]')
if [ -z "$EXISTING_PR" ]; then
echo "No existing PR found, creating a new one."
gh pr create --base master --head ${{ env.branch_name }} --title "Emojis Auto Update" --body "This PR was created automatically by the Emojis Auto Update workflow." --label emojis
else
echo "An existing PR was found: $EXISTING_PR"
fi
env:
GH_TOKEN: ${{ github.token }}