Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 18 additions & 70 deletions .github/workflows/autobuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ concurrency:
group: 'autobuild'
cancel-in-progress: true

permissions:
contents: write
pull-requests: write

jobs:
update-dist:
runs-on: ubuntu-latest
Expand All @@ -25,102 +29,46 @@ jobs:
- name: Install dependencies
run: npm install

- name: Run format
run: npm run format

- name: Run pack
run: npm run pack

- name: Check changed files
id: changed-files
shell: bash
run: |
CHANGED_FILES=$(git diff --name-only)

if [ -z "$CHANGED_FILES" ]; then
echo "No uncommitted changes detected."
echo "any_changed=false" >> $GITHUB_OUTPUT
echo "all_changed_files=''" >> $GITHUB_OUTPUT
else
echo "Uncommitted changes detected: $CHANGED_FILES"
echo "any_changed=true" >> $GITHUB_OUTPUT
# Format the changed files as a JSON array for proper parsing
CHANGED_FILES_JSON=$(echo "$CHANGED_FILES" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "all_changed_files=$CHANGED_FILES_JSON" >> $GITHUB_OUTPUT
fi

- name: Set current date as integer
if: steps.changed-files.outputs.any_changed == 'true'
id: date
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT

- name: Set Branch Name
if: steps.changed-files.outputs.any_changed == 'true'
id: set-branch
run: echo "branch_name=autobuild-${{ steps.date.outputs.date }}" >> $GITHUB_OUTPUT

- name: Configure Git
if: steps.changed-files.outputs.any_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

- name: Create and checkout branch
if: steps.changed-files.outputs.any_changed == 'true'
run: git checkout -b ${{ steps.set-branch.outputs.branch_name }}

- name: Add changed files
if: steps.changed-files.outputs.any_changed == 'true'
run: |
# Add only the changed files from the previous step
echo 'Changed files: ${{ steps.changed-files.outputs.all_changed_files }}'

# Parse the JSON array of changed files
echo '${{ steps.changed-files.outputs.all_changed_files }}' | jq -c '.[]' | while read -r file; do
# Remove quotes from the file path
file=$(echo $file | tr -d '"')

if [[ $file == dist/* ]]; then
git add "$file"
echo "Adding $file to commit"
fi
done

- name: Commit changes
if: steps.changed-files.outputs.any_changed == 'true'
id: commit
continue-on-error: true
run: |
# Check if there are any staged changes to commit
if git diff --staged --quiet; then
echo "No changes to commit in dist/ directory"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
git commit -m "[autobuild] dist update"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi

- name: Push branch
if: steps.changed-files.outputs.any_changed == 'true' && steps.commit.outputs.has_changes == 'true'
run: git push -u origin ${{ steps.set-branch.outputs.branch_name }}

- name: Create Pull Request
if: steps.changed-files.outputs.any_changed == 'true' && steps.commit.outputs.has_changes == 'true'
id: create-pr
uses: peter-evans/create-pull-request@v6
id: create_pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.set-branch.outputs.branch_name }}
title: "[AUTOBUILD] ${{ steps.date.outputs.date }}"
body: "Auto-generated update to dist/ from latest main push"
base: main
labels: autobuild
labels: |
autobuild
commit-message: "autobuild"
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
delete-branch: true
signoff: false
maintainer-can-modify: false

- name: Sleep for 30 seconds
if: steps.changed-files.outputs.any_changed == 'true' && steps.commit.outputs.has_changes == 'true'
if: ${{ steps.create_pr.outputs.pull-request-number }}
uses: juliangruber/sleep-action@v2.0.0
with:
time: 30s

- name: Auto-merge PR
if: steps.changed-files.outputs.any_changed == 'true' && steps.commit.outputs.has_changes == 'true'
if: ${{ steps.create_pr.outputs.pull-request-number }}
uses: pascalgn/automerge-action@v0.15.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down