fix: explicit file list for release, handle missing labels in auto-pr #8
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: Auto PR | |
| on: | |
| push: | |
| branches: | |
| - 'feature/**' | |
| - 'bugfix/**' | |
| - 'hotfix/**' | |
| - 'release/**' | |
| - 'major/**' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| create-pr: | |
| name: Create Pull Request | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine PR type and labels | |
| id: pr-meta | |
| run: | | |
| BRANCH="${GITHUB_REF#refs/heads/}" | |
| echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
| if [[ "$BRANCH" == feature/* ]]; then | |
| echo "type=feature" >> $GITHUB_OUTPUT | |
| echo "label=enhancement" >> $GITHUB_OUTPUT | |
| TITLE_PREFIX="feat" | |
| elif [[ "$BRANCH" == bugfix/* ]]; then | |
| echo "type=bugfix" >> $GITHUB_OUTPUT | |
| echo "label=bug" >> $GITHUB_OUTPUT | |
| TITLE_PREFIX="fix" | |
| elif [[ "$BRANCH" == hotfix/* ]]; then | |
| echo "type=hotfix" >> $GITHUB_OUTPUT | |
| echo "label=hotfix,urgent" >> $GITHUB_OUTPUT | |
| TITLE_PREFIX="hotfix" | |
| elif [[ "$BRANCH" == release/* ]]; then | |
| echo "type=release" >> $GITHUB_OUTPUT | |
| echo "label=release" >> $GITHUB_OUTPUT | |
| TITLE_PREFIX="release" | |
| elif [[ "$BRANCH" == major/* ]]; then | |
| echo "type=major" >> $GITHUB_OUTPUT | |
| echo "label=breaking-change" >> $GITHUB_OUTPUT | |
| TITLE_PREFIX="major" | |
| fi | |
| # Extract description from branch name | |
| DESC=$(echo "$BRANCH" | sed 's|^[^/]*/||' | tr '-' ' ' | tr '_' ' ') | |
| echo "title=$TITLE_PREFIX: $DESC" >> $GITHUB_OUTPUT | |
| - name: Check for existing PR | |
| id: check-pr | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| EXISTING=$(gh pr list --head "${{ steps.pr-meta.outputs.branch }}" --json number --jq '.[0].number') | |
| echo "existing=$EXISTING" >> $GITHUB_OUTPUT | |
| - name: Create Pull Request | |
| if: steps.check-pr.outputs.existing == '' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Create PR without labels first (labels may not exist) | |
| PR_URL=$(gh pr create \ | |
| --title "${{ steps.pr-meta.outputs.title }}" \ | |
| --body "## Summary | |
| Auto-generated PR for branch \`${{ steps.pr-meta.outputs.branch }}\` | |
| ## Type | |
| - ${{ steps.pr-meta.outputs.type }} | |
| ## Checklist | |
| - [ ] Code compiles without errors | |
| - [ ] Tests pass | |
| - [ ] Documentation updated (if needed) | |
| " \ | |
| --base master \ | |
| --draft) | |
| echo "Created PR: $PR_URL" | |
| # Try to add labels (may fail if labels don't exist, that's ok) | |
| gh pr edit "$PR_URL" --add-label "${{ steps.pr-meta.outputs.label }}" || echo "Note: Could not add labels (they may not exist in repo)" |