Feat/file index #51
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
| # .github/workflows/beta-release.yml | |
| name: "Automatic Beta Release on PR Commit" | |
| on: | |
| pull_request: | |
| # Trigger on PR creation or when new commits are pushed | |
| types: [opened, synchronize] | |
| # IMPORTANT: Change 'main' to your default branch if it's different (e.g., 'master') | |
| branches: | |
| - master | |
| push: | |
| # Only trigger on push to specific branches (more secure) | |
| branches: | |
| - master | |
| - "feat/**" | |
| - "release/**" | |
| env: | |
| PLUGIN_NAME: obsidian-task-genius | |
| # Grant permissions for the action to create a release | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| build-and-release-beta: | |
| if: | | |
| contains(github.event.head_commit.message, '[release-beta]') && ( | |
| (github.event_name == 'push' && github.actor == github.repository_owner) || | |
| (github.event_name == 'pull_request' && github.event.pull_request.author_association == 'OWNER') | |
| ) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: "Checkout code" | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # Check if any recent commits contain [release-beta] tag | |
| - name: "Check for release-beta tag in commits" | |
| id: check_release_tag | |
| run: | | |
| SHOULD_RELEASE="false" | |
| # Security check: only allow releases from the main repository | |
| REPO_OWNER="${{ github.repository_owner }}" | |
| REPO_NAME="${{ github.repository }}" | |
| echo "Repository: $REPO_NAME, Owner: $REPO_OWNER" | |
| # Add your expected repository info here for extra security | |
| # EXPECTED_REPO="your-username/your-repo-name" | |
| # if [ "$REPO_NAME" != "$EXPECTED_REPO" ]; then | |
| # echo "Release not allowed from repository: $REPO_NAME" | |
| # echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT | |
| # exit 0 | |
| # fi | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "Checking PR commits for [release-beta] tag..." | |
| # Check the latest commit in the PR | |
| LATEST_COMMIT_MSG=$(git log -1 --pretty=format:"%s") | |
| echo "Latest commit message: $LATEST_COMMIT_MSG" | |
| if echo "$LATEST_COMMIT_MSG" | grep -q "\[release-beta\]"; then | |
| echo "Found [release-beta] tag in latest commit" | |
| SHOULD_RELEASE="true" | |
| fi | |
| # Check user permissions (more restrictive) | |
| USER_ASSOCIATION="${{ github.event.pull_request.author_association }}" | |
| PR_AUTHOR="${{ github.event.pull_request.user.login }}" | |
| echo "PR author: $PR_AUTHOR, Association: $USER_ASSOCIATION" | |
| # Only allow OWNER and COLLABORATOR to trigger releases | |
| if [ "$USER_ASSOCIATION" != "OWNER" ] && [ "$USER_ASSOCIATION" != "COLLABORATOR" ]; then | |
| echo "User association '$USER_ASSOCIATION' is not authorized for releases" | |
| SHOULD_RELEASE="false" | |
| fi | |
| # Additional check: only allow specific users (optional - uncomment and customize) | |
| # ALLOWED_USERS="Quorafind,other-username" | |
| # if ! echo "$ALLOWED_USERS" | grep -q "$PR_AUTHOR"; then | |
| # echo "User '$PR_AUTHOR' is not in allowed users list" | |
| # SHOULD_RELEASE="false" | |
| # fi | |
| elif [ "${{ github.event_name }}" = "push" ]; then | |
| echo "Checking push commit for [release-beta] tag..." | |
| COMMIT_MSG="${{ github.event.head_commit.message }}" | |
| PUSH_AUTHOR="${{ github.event.head_commit.author.username }}" | |
| echo "Commit message: $COMMIT_MSG" | |
| echo "Push author: $PUSH_AUTHOR" | |
| if echo "$COMMIT_MSG" | grep -q "\[release-beta\]"; then | |
| echo "Found [release-beta] tag in push commit" | |
| # Check if pusher is authorized (optional - uncomment and customize) | |
| # ALLOWED_PUSH_USERS="Quorafind,other-username" | |
| # if ! echo "$ALLOWED_PUSH_USERS" | grep -q "$PUSH_AUTHOR"; then | |
| # echo "User '$PUSH_AUTHOR' is not authorized to trigger releases via push" | |
| # SHOULD_RELEASE="false" | |
| # else | |
| # SHOULD_RELEASE="true" | |
| # fi | |
| SHOULD_RELEASE="true" | |
| fi | |
| fi | |
| echo "SHOULD_RELEASE=$SHOULD_RELEASE" >> $GITHUB_OUTPUT | |
| echo "Should release: $SHOULD_RELEASE" | |
| - name: "Use Node.js 22" | |
| if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: "Install pnpm" | |
| if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true' | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| - name: "Install dependencies" | |
| if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true' | |
| run: pnpm install | |
| - name: "Get version from package.json" | |
| if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true' | |
| id: get_version | |
| run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | |
| - name: "Get commit messages since last tag" | |
| if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true' | |
| id: get_commits | |
| run: | | |
| # Get the most recent tag (including pre-releases) | |
| LAST_TAG=$(git tag --sort=-version:refname | head -n 1 2>/dev/null || echo "") | |
| if [ -z "$LAST_TAG" ]; then | |
| echo "No previous tag found, getting all commits from the beginning" | |
| COMMIT_MESSAGES=$(git log --pretty=format:"- %s (%an) [%h](https://github.com/${{ github.repository }}/commit/%H)" --no-merges) | |
| else | |
| echo "Getting commits since last tag: $LAST_TAG" | |
| TAG_COMMIT=$(git rev-list -n 1 $LAST_TAG) | |
| COMMIT_MESSAGES=$(git log ${TAG_COMMIT}..HEAD --pretty=format:"- %s (%an) [%h](https://github.com/${{ github.repository }}/commit/%H)" --no-merges) | |
| fi | |
| if [ -z "$COMMIT_MESSAGES" ]; then | |
| COMMIT_MESSAGES="- No new commits since last tag" | |
| fi | |
| echo "COMMIT_MESSAGES<<EOF" >> $GITHUB_ENV | |
| echo "$COMMIT_MESSAGES" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV | |
| - name: "Build and package plugin" | |
| if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true' | |
| id: build | |
| run: | | |
| pnpm run build | |
| mkdir ${{ env.PLUGIN_NAME }} | |
| cp main.js manifest.json styles.css ${{ env.PLUGIN_NAME }}/ | |
| zip -r ${{ env.PLUGIN_NAME }}-${{ env.VERSION }}.zip ./${{ env.PLUGIN_NAME }} | |
| - name: "Create Beta Pre-Release" | |
| if: steps.check_release_tag.outputs.SHOULD_RELEASE == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| body: | | |
| ${{ github.event_name == 'pull_request' && format('🚀 Automated beta release for PR #{0}', github.event.pull_request.number) || '🚀 Automated beta release' }} | |
| ## 📝 Changes since last tag${{ env.LAST_TAG && format(' ({0})', env.LAST_TAG) || '' }}: | |
| ${{ env.COMMIT_MESSAGES }} | |
| --- | |
| ${{ github.event_name == 'pull_request' && github.event.pull_request.body || '' }} | |
| prerelease: true | |
| tag_name: "v${{ env.VERSION }}" | |
| name: "Beta Release v${{ env.VERSION }}" | |
| files: | | |
| ${{ env.PLUGIN_NAME }}-${{ env.VERSION }}.zip | |
| main.js | |
| manifest.json | |
| styles.css |