name: Auto PR to main when version changes on: push: branches: - canary permissions: contents: write pull-requests: write jobs: create-pr: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v7 with: fetch-depth: 0 - name: Get version from package.json run: echo "VERSION=$(jq -r .version ./apps/dokploy/package.json)" >> "$GITHUB_ENV" - name: Get latest GitHub tag run: | LATEST_TAG=$(git ls-remote --tags origin | awk -F'/' '{print $3}' | sort -V | tail -n1) echo "LATEST_TAG=$LATEST_TAG" >> "$GITHUB_ENV" echo "$LATEST_TAG" - name: Compare versions run: | if [ "$VERSION" != "$LATEST_TAG" ]; then VERSION_CHANGED="true" else VERSION_CHANGED="false" fi echo "VERSION_CHANGED=$VERSION_CHANGED" >> "$GITHUB_ENV" echo "Comparing versions:" echo "Current version: $VERSION" echo "Latest tag: $LATEST_TAG" echo "Version changed: $VERSION_CHANGED" - name: Check if a PR already exists run: | PR_EXISTS=$(gh pr list --state open --base main --head canary --json number --jq '. | length') echo "PR_EXISTS=$PR_EXISTS" >> "$GITHUB_ENV" env: GH_TOKEN: ${{ secrets.GH_PAT }} - name: Create Pull Request if: env.VERSION_CHANGED == 'true' && env.PR_EXISTS == '0' run: | git config --global user.name "github-actions[bot]" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git fetch origin main git checkout canary git push origin canary gh pr create \ --title "🚀 Release $VERSION" \ --body " This PR promotes changes from \`canary\` to \`main\` for version $VERSION. ### 🔍 Changes Include: - Version bump to $VERSION - All changes from canary branch ### ✅ Pre-merge Checklist: - [ ] All tests passing - [ ] Documentation updated - [ ] Docker images built and tested > 🤖 This PR was automatically generated by [GitHub Actions](https://github.com/actions)" \ --base main \ --head canary \ --label "release" --label "automated pr" || true \ --reviewer siumauricio \ --assignee siumauricio env: GH_TOKEN: ${{ github.token }}