From 9283be652d421257fb818d9498bdc35e679559a3 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Sat, 3 May 2025 03:47:04 -0500 Subject: [PATCH] [GitHub] Create release action workflows (#5743) * Create release actions * Add release branch to push/pull events that invoke test workflows --- .github/workflows/create-release.yml | 73 ++++++++++++++++++++++ .github/workflows/deploy-beta.yml | 15 +++-- .github/workflows/post-release-deleted.yml | 12 ++++ .github/workflows/tests.yml | 2 + 4 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/create-release.yml create mode 100644 .github/workflows/post-release-deleted.yml diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 00000000000..35a31f6b4d1 --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,73 @@ +name: Create Release Branch +on: + workflow_dispatch: + inputs: + versionName: + description: "Name of version (i.e. 1.9.0)" + type: string + required: true + confirmVersion: + type: string + required: true + description: "Confirm version name" + +# explicitly specify the necessary scopes +permissions: + pull-requests: write + actions: write + contents: write + +jobs: + create-release: + if: github.repository == 'pagefaultgames/pokerogue' && (vars.BETA_DEPLOY_BRANCH == '' || ! startsWith(vars.BETA_DEPLOY_BRANCH, 'release')) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed for github cli commands + runs-on: ubuntu-latest + steps: + - name: Validate provided version + # Ensure version matches confirmation and conforms to expected pattern. + run: | + if [[ "${{ github.event.inputs.versionName }}" != "${{ github.event.inputs.confirmVersion }}" ]]; then + echo "Version name does not match confirmation. Exiting." + exit 1 + fi + if [[ ! "${{ github.event.inputs.versionName }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Version name must follow the format X.Y.Z where X, Y, and Z are all numbers. Exiting..." + exit 1 + fi + shell: bash + - name: Check out code + uses: actions/checkout@v4 + with: + submodules: "recursive" + # Always base off of beta branch, regardless of the branch the workflow was triggered from. + ref: beta + - name: Create release branch + run: git checkout -b release + # In order to be able to open a PR into beta, we need the branch to have at least one change. + - name: Overwrite RELEASE file + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + echo "Release v${{ github.event.inputs.versionName }}" > RELEASE + git add RELEASE + git commit -m "Stage release v${{ github.event.inputs.versionName }}" + - name: Push new branch + run: git push origin release + # The repository variable is used by the deploy-beta workflow to determine whether to deploy from beta or release. + - name: Set repository variable + run: GITHUB_TOKEN="${{ secrets.RW_VARS_PAT }}" gh variable set BETA_DEPLOY_BRANCH --body "release" + - name: Create pull request to main + run: | + gh pr create --base main \ + --head release \ + --title "Release v${{ github.event.inputs.versionName }} to main" \ + --body "This PR is for the release of v${{ github.event.inputs.versionName }}, and was created automatically by the GitHub Actions workflow invoked by ${{ github.actor }}" \ + --draft + - name: Create pull request to beta + run: | + gh pr create --base beta \ + --head release \ + --title "Release v${{ github.event.inputs.versionName }} to beta" \ + --body "This PR is for the release of v${{ github.event.inputs.versionName }}, and was created automatically by the GitHub Actions workflow invoked by ${{ github.actor }}" \ + --draft diff --git a/.github/workflows/deploy-beta.yml b/.github/workflows/deploy-beta.yml index 8b0e33a18c4..90b3008c8e9 100644 --- a/.github/workflows/deploy-beta.yml +++ b/.github/workflows/deploy-beta.yml @@ -4,18 +4,23 @@ on: push: branches: - beta + - release + workflow_run: + types: completed + workflows: ["Post Release Deleted"] jobs: deploy: - if: github.repository == 'pagefaultgames/pokerogue' + if: github.repository == 'pagefaultgames/pokerogue' && github.ref_name == ${{ vars.BETA_DEPLOY_BRANCH || 'beta' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: - submodules: 'recursive' + submodules: "recursive" + ref: ${{ vars.BETA_DEPLOY_BRANCH || 'beta'}} - uses: actions/setup-node@v4 with: - node-version-file: '.nvmrc' + node-version-file: ".nvmrc" - name: Install dependencies run: npm ci - name: Build @@ -30,5 +35,5 @@ jobs: chmod 600 ~/.ssh/* ssh-keyscan -H ${{ secrets.BETA_SSH_HOST }} >> ~/.ssh/known_hosts - name: Deploy build on server - run: | - rsync --del --no-times --checksum -vrm dist/* ${{ secrets.BETA_SSH_USER }}@${{ secrets.BETA_SSH_HOST }}:${{ secrets.BETA_DESTINATION_DIR }} \ No newline at end of file + run: | + rsync --del --no-times --checksum -vrm dist/* ${{ secrets.BETA_SSH_USER }}@${{ secrets.BETA_SSH_HOST }}:${{ secrets.BETA_DESTINATION_DIR }} diff --git a/.github/workflows/post-release-deleted.yml b/.github/workflows/post-release-deleted.yml new file mode 100644 index 00000000000..65447e7826b --- /dev/null +++ b/.github/workflows/post-release-deleted.yml @@ -0,0 +1,12 @@ +name: Post Release Deleted +on: + delete: + +jobs: + # Set the BETA_DEPLOY_BRANCH variable to beta when a release branch is deleted + update-release-var: + if: github.repository == 'pagefaultgames/pokerogue' && github.event.ref_type == 'branch' && github.event.ref == 'release' + runs-on: ubuntu-latest + steps: + - name: Set BETA_DEPLOY_BRANCH to beta + run: GITHUB_TOKEN="${{ secrets.RW_VARS_PAT }}" gh variable set BETA_DEPLOY_BRANCH --body "beta" --repo "pagefaultgames/pokerogue" \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ccc8604ff7e..d9db8401f8e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,6 +7,7 @@ on: branches: - main # Trigger on push events to the main branch - beta # Trigger on push events to the beta branch + - release # Trigger on push events to the release branch # go upvote https://github.com/actions/runner/issues/1182 and yell at microsoft until they fix this or ditch yml for workflows paths: # src and test files @@ -32,6 +33,7 @@ on: branches: - main # Trigger on pull request events targeting the main branch - beta # Trigger on pull request events targeting the beta branch + - release # Trigger on pull request events targeting the release branch paths: # go upvote https://github.com/actions/runner/issues/1182 and yell at microsoft because until then we have to duplicate this # src and test files - "src/**"