mirror of
https://github.com/Paillat-dev/discord-emojis.git
synced 2026-01-02 00:56:19 +00:00
96 lines
3.2 KiB
YAML
96 lines
3.2 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@v4
|
|
- uses: fregante/setup-git-user@v1
|
|
|
|
- name: Install the latest version of uv
|
|
uses: astral-sh/setup-uv@v6
|
|
|
|
- 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: |
|
|
uv run src
|
|
EXIT_CODE=$?
|
|
echo "exit_code=$EXIT_CODE" >> $GITHUB_ENV
|
|
if [ $EXIT_CODE -eq 0 ]; then
|
|
echo "changes_detected=true" >> $GITHUB_ENV
|
|
elif [ $EXIT_CODE -eq 3 ]; then
|
|
echo "changes_detected=false" >> $GITHUB_ENV
|
|
# Transform it to 0 to avoid failing the workflow
|
|
exit 0
|
|
else
|
|
echo "Script failed with exit code $EXIT_CODE"
|
|
exit $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 }} |