diff --git a/.github/workflows/develop-update.yml b/.github/workflows/develop-update.yml deleted file mode 100644 index 0840da6..0000000 --- a/.github/workflows/develop-update.yml +++ /dev/null @@ -1,132 +0,0 @@ -# This workflow opens a PR between main and develop branches to keep develop up to date. -name: "Update Develop Branch" - -on: - push: - branches: - - main - workflow_call: - inputs: - repository: - description: "Allowed repository for workflow to run in. Example `ctfpilot/hello-world`." - required: true - type: string - pr_description: - description: "Additional description to add to the PR body." - required: false - type: string - -permissions: - contents: read - pull-requests: write - issues: write - -jobs: - update-develop: - name: "Update Develop Branch" - runs-on: ubuntu-latest - if: github.repository == ( inputs.repository || 'ctfpilot/ci') && github.ref == 'refs/heads/main' - steps: - - name: "Checkout" - uses: actions/checkout@v4 - with: - ref: main - - # Ensure diff between main and develop - - name: "Check if there is a diff between main and develop" - id: check_diff - run: | - git fetch origin develop - # Check if there are commits in main that aren't in develop - COMMITS=$(git rev-list origin/develop..main --count) - if [ "$COMMITS" -eq 0 ]; then - echo "No commits found in main that aren't in develop. Develop is up to date or ahead." - echo "diff=false" >> $GITHUB_OUTPUT - else - echo "Found $COMMITS commit(s) in main that aren't in develop." - echo "diff=true" >> $GITHUB_OUTPUT - fi - - name: "Check if existing PR exists" - if: steps.check_diff.outputs.diff == 'true' - id: check_pr - uses: actions/github-script@v8 - with: - script: | - const { data: pullRequests } = await github.rest.pulls.list({ - owner: context.repo.owner, - repo: context.repo.repo, - head: 'main', - base: 'develop', - state: 'open' - }); - if (pullRequests.length > 0) { - return 'true'; - } else { - return 'false'; - } - result-encoding: string - - # Ensure labels exist - - name: 'Ensure "develop-update" label is created' - if: steps.check_pr.outputs.result == 'false' - uses: actions/github-script@v8 - with: - script: | - try { - await github.rest.issues.getLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'develop-update' - }); - } catch (error) { - if (error.status === 404) { - await github.rest.issues.createLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'develop-update', - color: '0E8A16', - description: 'Indicates that this PR updates the develop branch to match the latest version of main.' - }); - } else { - throw error; - } - } - - name: 'Ensure "ci" label is created' - if: steps.check_pr.outputs.result == 'false' - uses: actions/github-script@v8 - with: - script: | - try { - await github.rest.issues.getLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'ci' - }); - } catch (error) { - if (error.status === 404) { - await github.rest.issues.createLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'ci', - color: 'EDEDED', - description: 'Indicates that this PR is related to continuous integration.' - }); - } else { - throw error; - } - } - - # PR Creation - - name: "Create Pull Request to update develop branch, and merge it" - id: create_pr - if: steps.check_diff.outputs.diff == 'true' && steps.check_pr.outputs.result == 'false' - run: | - PR_BODY='Merge main into develop to update the develop branch to the latest version' - if [ -n "$PR_DESCRIPTION" ]; then - PR_BODY="${PR_BODY}"$'\n\n'"${PR_DESCRIPTION}" - fi - URL=$(gh pr create -B develop -H main --title 'CI: Update develop to match main' --body "$PR_BODY" --label develop-update --label ci) - echo "URL=$URL" >> $GITHUB_OUTPUT - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_DESCRIPTION: ${{ inputs.pr_description }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 591cc65..43381af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,6 +43,29 @@ jobs: with: fetch-depth: 0 persist-credentials: false + + - name: "Check if develop is up to date with main" + id: check_diff + if: github.ref == 'refs/heads/develop' + run: | + git fetch origin main + # Check if there are commits in main that aren't in develop + COMMITS=$(git rev-list origin/develop..origin/main --count) + if [ "$COMMITS" -eq 0 ]; then + echo "No commits found in main that aren't in develop. Develop is up to date or ahead." + echo "diff=false" >> $GITHUB_OUTPUT + else + echo "Found $COMMITS commit(s) in main that aren't in develop." + echo "diff=true" >> $GITHUB_OUTPUT + fi + + - name: Fail if develop is not up to date with main + if: steps.check_diff.outputs.diff == 'true' && github.ref == 'refs/heads/develop' + run: | + echo "Develop branch is not up to date with main. Please update develop before releasing." + echo "::error title=Develop branch out of date::Develop branch is not up to date with main. Please update develop before releasing." + exit 1 + - name: Setup Node.js uses: actions/setup-node@v6 with: diff --git a/README.md b/README.md index f6afeb2..c4155e6 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ This workflow contains the release system used throughout CTF Pilot. The workflow requires the `repository` input to be specified. +When the workflow runs on a push to `develop`, it will fail if `main` is ahead of `develop`. + #### Inputs - `repository`: Allowed repository for workflow to run in. Example `ctfpilot/hello-world`. @@ -166,41 +168,6 @@ jobs: repository: ``` -### Develop Update - -This workflow updates the `develop` branch to match the latest version of the `main` branch. - -The workflow requires the `repository` input to be specified. - -If no commits are found in `main` that aren't in `develop`, or an existing PR between main and develop exists, the workflow will exit without merging changes, but will create a PR if possible. - -#### Inputs - -- `repository`: Allowed repository for workflow to run in. Example `ctfpilot/hello-world`. -- `pr_description`: Additional description to add to the PR body. - -#### How to use - -```yml -name: "Update Develop Branch" - -on: - push: - branches: - - main - -jobs: - CLAAssistant: - permissions: - contents: read - pull-requests: write - issues: write - name: "Update Develop Branch" - uses: ctfpilot/ci/.github/workflows/develop-update.yml@ - with: - repository: -``` - ## Contributing We welcome contributions of all kinds, from **code** and **documentation** to **bug reports** and **feedback**!