nusr is releasing app π #27
Workflow file for this run
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: Create Release PR | |
| run-name: ${{ github.actor }} is releasing app π | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| types: | |
| - closed | |
| branches: | |
| - "main" | |
| jobs: | |
| create-pre-release-pull-request: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'workflow_dispatch' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: main | |
| fetch-depth: 1 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.x" | |
| - name: Install Yarn | |
| run: npm install -g yarn | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Install dependencies and execute release | |
| run: | | |
| yarn | |
| yarn release:patch | |
| - name: Get modified files and validate | |
| id: validate-files | |
| run: | | |
| echo "π Checking staged files..." | |
| modified_files=$(git ls-files -m -o --exclude-standard) | |
| if [ -z "$modified_files" ]; then | |
| echo "β No modified files found" | |
| exit 1 | |
| fi | |
| # Extract package.json and CHANGELOG.md paths | |
| package_json_path=$(echo "$modified_files" | grep "package.json" | head -n 1) | |
| changelog_path=$(echo "$modified_files" | grep "CHANGELOG.md" | head -n 1) | |
| if [ -z "$package_json_path" ]; then | |
| echo "β package.json not found among modified files" | |
| exit 1 | |
| fi | |
| if [ -z "$changelog_path" ]; then | |
| echo "β CHANGELOG.md not found among modified files" | |
| exit 1 | |
| fi | |
| # Extract changelog content | |
| latest_changelog=$(git diff --no-color "$changelog_path" | grep -E '^(\+[^+]|-)' | grep -Ev '^--- a/' | sed 's/^+//;s/^-//') | |
| if [ -z "$latest_changelog" ]; then | |
| echo "β CHANGELOG.md has no changes" | |
| exit 1 | |
| fi | |
| # Save to temp file | |
| changelog_temp_file=$(mktemp) | |
| echo "$latest_changelog" > "$changelog_temp_file" | |
| # Extract package info | |
| package_name=$(jq -r '.name' "$package_json_path") | |
| package_name="${package_name//@/}" | |
| package_version=$(jq -r '.version' "$package_json_path") | |
| echo "π¦ Package: $package_name" | |
| echo "π·οΈ Version: $package_version" | |
| # Set outputs | |
| echo "package_name=$package_name" >> $GITHUB_OUTPUT | |
| echo "package_version=$package_version" >> $GITHUB_OUTPUT | |
| echo "changelog_temp_file=$changelog_temp_file" >> $GITHUB_OUTPUT | |
| echo "branchName=pre-release/$package_name/$package_version" >> $GITHUB_OUTPUT | |
| - name: Check branch and create commit | |
| run: | | |
| branchName="${{ steps.validate-files.outputs.branchName }}" | |
| echo "πΏ Branch: $branchName" | |
| if git ls-remote --exit-code --heads origin "$branchName"; then | |
| echo "β Branch already exists" | |
| exit 1 | |
| fi | |
| git checkout -B "$branchName" | |
| git add -A | |
| git commit -m "chore(RELEASE): ${{ steps.validate-files.outputs.package_version }}" | |
| git push --set-upstream origin "$branchName" | |
| echo "β Branch and commit created" | |
| - name: Create PR | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| changelog_content=$(cat "${{ steps.validate-files.outputs.changelog_temp_file }}") | |
| default_branch=$(git remote show origin | grep 'HEAD branch' | awk '{print $NF}') | |
| echo "π Creating PR..." | |
| pr_url=$(gh pr create \ | |
| --title "chore(RELEASE): ${{ steps.validate-files.outputs.package_version }}" \ | |
| --body "$changelog_content" \ | |
| --base "$default_branch" \ | |
| --head "${{ steps.validate-files.outputs.branchName }}") | |
| echo "β PR created: $pr_url" | |
| # Cleanup | |
| rm -f "${{ steps.validate-files.outputs.changelog_temp_file }}" | |
| release: | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'pre-release/excel-collab/') | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: "main" | |
| fetch-depth: 1 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.x" | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Fetch PR metadata and create release | |
| id: release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "π Fetching PR metadata..." | |
| PR_NUMBER=${{ github.event.pull_request.number }} | |
| PR_META=$(gh pr view "$PR_NUMBER" --json number,title,body,mergeCommit) | |
| PR_TITLE=$(echo "$PR_META" | jq -r '.title') | |
| PR_BODY=$(echo "$PR_META" | jq -r '.body') | |
| TAG_NAME=$(echo "$PR_TITLE" | sed -e 's/^chore(RELEASE): *//' -e 's/ *$//') | |
| COMMIT_ID=$(echo "$PR_META" | jq -r '.mergeCommit.oid') | |
| if [ -z "$COMMIT_ID" ]; then | |
| echo "β No merge commit found" | |
| exit 1 | |
| fi | |
| # Validate version format | |
| if [[ ! "$TAG_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-hotfix-[0-9]+)?$ ]]; then | |
| echo "β Invalid version format: $TAG_NAME" | |
| exit 1 | |
| fi | |
| echo "π Creating release: $TAG_NAME" | |
| # Create release using gh CLI | |
| gh release create "$TAG_NAME" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "$TAG_NAME" \ | |
| --target "$COMMIT_ID" \ | |
| --notes "$PR_BODY" | |
| echo "β Release created successfully: $TAG_NAME" | |
| - name: Trigger publish workflow | |
| if: always() | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "π Triggering publish workflow..." | |
| # Check if release was created successfully | |
| if [ "${{ job.status }}" != "success" ]; then | |
| echo "β Release job failed, skipping publish trigger" | |
| exit 0 | |
| fi | |
| # Trigger publish workflow using workflow_dispatch event | |
| gh workflow run publish.yml \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --ref "main" \ | |
| || echo "β οΈ Failed to trigger publish workflow" | |
| echo "β Publish workflow triggered" |