Pull Request Conference Sort & All-contrib #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Pull Request Conference Sort & All-contrib | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '_data/conferences.yml' | ||
| types: | ||
| - closed | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
| inputs: | ||
| pr_number: | ||
| description: 'PR number to reference (leave empty for sort-only)' | ||
| required: false | ||
| type: string | ||
| contributor: | ||
| description: 'GitHub username to add as contributor (leave empty to skip)' | ||
| required: false | ||
| type: string | ||
| jobs: | ||
| process-changes: | ||
| runs-on: ubuntu-latest | ||
| # Only check for merged PR when triggered by a pull_request event | ||
| if: github.event_name != 'pull_request' || github.event.pull_request.merged == true | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Setup Pixi | ||
| uses: prefix-dev/[email protected] | ||
| - name: Set variables | ||
| id: vars | ||
| run: | | ||
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | ||
| # For PR-triggered workflow | ||
| echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | ||
| echo "contributor=${{ github.event.pull_request.user.login }}" >> $GITHUB_OUTPUT | ||
| echo "branch_name=automated-updates-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | ||
| else | ||
| # For manually triggered workflow | ||
| PR_REF="${{ github.event.inputs.pr_number }}" | ||
| CONTRIBUTOR="${{ github.event.inputs.contributor }}" | ||
| if [[ -n "$PR_REF" ]]; then | ||
| echo "pr_number=$PR_REF" >> $GITHUB_OUTPUT | ||
| echo "branch_name=automated-updates-$PR_REF" >> $GITHUB_OUTPUT | ||
| else | ||
| # Generate a timestamp if no PR number provided | ||
| TIMESTAMP=$(date +%Y%m%d%H%M%S) | ||
| echo "pr_number=manual-$TIMESTAMP" >> $GITHUB_OUTPUT | ||
| echo "branch_name=automated-updates-$TIMESTAMP" >> $GITHUB_OUTPUT | ||
| fi | ||
| if [[ -n "$CONTRIBUTOR" ]]; then | ||
| echo "contributor=$CONTRIBUTOR" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "contributor=" >> $GITHUB_OUTPUT | ||
| fi | ||
| fi | ||
| - name: Create changes | ||
| id: changes | ||
| run: | | ||
| # Create a new branch | ||
| git checkout -b ${{ steps.vars.outputs.branch_name }} | ||
| # Run sort command | ||
| pixi run sort | ||
| # Add contributor if specified | ||
| if [[ -n "${{ steps.vars.outputs.contributor }}" ]]; then | ||
| pixi run install | ||
| pixi run add ${{ steps.vars.outputs.contributor }} conference | ||
| CONTRIBUTOR_MSG="* Add ${{ steps.vars.outputs.contributor }} as contributor" | ||
| else | ||
| CONTRIBUTOR_MSG="" | ||
| fi | ||
| # Check if there are changes | ||
| if ! git diff --quiet; then | ||
| echo "has_changes=true" >> $GITHUB_OUTPUT | ||
| # Stage and commit changes | ||
| git config --global user.name 'github-actions[bot]' | ||
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
| git add _data/* .all-contributorsrc README.md CONTRIBUTING.md | ||
| # Create commit message | ||
| COMMIT_MSG="chore: updates" | ||
| COMMIT_MSG="$COMMIT_MSG\n\n* Sort conferences" | ||
| if [[ -n "$CONTRIBUTOR_MSG" ]]; then | ||
| COMMIT_MSG="$COMMIT_MSG\n$CONTRIBUTOR_MSG" | ||
| fi | ||
| git commit -m "$COMMIT_MSG" | ||
| # Push the branch to the remote repository | ||
| git push -u origin ${{ steps.vars.outputs.branch_name }} | ||
| else | ||
| echo "has_changes=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Create Pull Request | ||
| if: steps.changes.outputs.has_changes == 'true' | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| title: 'Automated updates from PR #${{ github.event.pull_request.number }}' | ||
| body: | | ||
|
Check failure on line 113 in .github/workflows/pr-sort.yml
|
||
| This PR was ${{ github.event_name == 'pull_request' && 'automatically created after merging' || 'manually triggered' }} ${{ steps.vars.outputs.pr_number }} | ||
| Changes include: | ||
| - Sorted conferences | ||
| ${{ steps.vars.outputs.contributor != '' && '- Added @'+ steps.vars.outputs.contributor+' as contributor') || '' }} | ||
| Please review and merge these automated updates. | ||
| branch: ${{ steps.vars.outputs.branch_name }} | ||
| base: main | ||
| delete-branch: true | ||