From 3f69915d914aca012086bb0a4d03639a4d04119c Mon Sep 17 00:00:00 2001 From: Kristen Wilkinson Date: Tue, 18 Jul 2023 14:08:21 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7Create=20add=20to=20proj=20workflow?= =?UTF-8?q?=20(#241)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Start work for issue #239 * feat: create add proj workflow * ci: update workflow to reusable workflow * pr-changes: change workflow version from v8.2.0 to v9.1.0 * pr-changes: update token ref * pr-changes: update `echo` to `Write-Host` * pr-changes: update token ref and `echo` to `Write-Host` * ci: improve status checks * ci: improve sync system workflows * ci: improve release workflow * ci: create prepare release workflow * ci: update renovate config branch * ci: update token references --------- Co-authored-by: Calvin Wilkinson Co-authored-by: Calvin Wilkinson <85414302+CalvinWilkinson@users.noreply.github.com> --- .../workflows/add-new--issue-to-project.yml | 18 +++++ .github/workflows/build-pr-status-check.yml | 41 ---------- .github/workflows/build-status-check.yml | 23 ++++++ .github/workflows/prepare-release.yml | 79 +++++++++++++++++++ .github/workflows/release.yml | 38 ++------- .github/workflows/sync-bot.yml | 19 ++--- .github/workflows/sync-issue-to-pr.yml | 24 ++++-- .github/workflows/sync-status-check.yml | 20 ++--- .../workflows/unit-test-pr-status-check.yml | 41 ---------- .github/workflows/unit-test-status-check.yml | 23 ++++++ renovate.json | 2 +- 11 files changed, 189 insertions(+), 139 deletions(-) create mode 100644 .github/workflows/add-new--issue-to-project.yml delete mode 100644 .github/workflows/build-pr-status-check.yml create mode 100644 .github/workflows/build-status-check.yml create mode 100644 .github/workflows/prepare-release.yml delete mode 100644 .github/workflows/unit-test-pr-status-check.yml create mode 100644 .github/workflows/unit-test-status-check.yml diff --git a/.github/workflows/add-new--issue-to-project.yml b/.github/workflows/add-new--issue-to-project.yml new file mode 100644 index 00000000..59adce29 --- /dev/null +++ b/.github/workflows/add-new--issue-to-project.yml @@ -0,0 +1,18 @@ +name: 🤖Add New Issue To Project + + +on: + issues: + types: opened + + +jobs: + add_new_issue_to_project: + name: Add New Issue + uses: KinsonDigital/Infrastructure/.github/workflows/add-issue-to-project.yml@v9.1.0 + with: + org-name: "${{ vars.ORGANIZATION_NAME }}" + org-project-name: "${{ vars.ORG_PROJECT_NAME }}" + project-name: "${{ vars.PROJECT_NAME }}" + secrets: + cicd-pat: ${{ secrets.CICD_TOKEN }} diff --git a/.github/workflows/build-pr-status-check.yml b/.github/workflows/build-pr-status-check.yml deleted file mode 100644 index eb051556..00000000 --- a/.github/workflows/build-pr-status-check.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: ✅Build Status Check -run-name: ✅Build Status Check ${{ github.base_ref == 'main' && '(Release Build)' || '(Debug Build)' }} - - -defaults: - run: - shell: pwsh - - -on: - workflow_dispatch: - pull_request: - branches: [main, preview] - - -jobs: - determine_build_config: - name: Determine Build Configuration - runs-on: ubuntu-latest - outputs: - build-config: ${{ steps.get-build-config.outputs.build-config }} - steps: - - name: Get Build Config - id: get-build-config - run: | - # If the destination branch that the pull request is merging into is the main, do a release build - if ( "${{ github.base_ref }}" -eq "main") { - "build-config=Release" >> $env:GITHUB_OUTPUT; - } else { # Any other branch than main, do a debug build - "build-config=Debug" >> $env:GITHUB_OUTPUT; - } - - - build_status_check: - name: Building ${{ vars.PROJECT_NAME }} - needs: [determine_build_config] - uses: KinsonDigital/Infrastructure/.github/workflows/build-csharp-project.yml@v7.2.0 - with: - project-name: "${{ vars.PROJECT_NAME }}" - build-config: ${{ needs.determine_build_config.outputs.build-config }} - net-sdk-version: "${{ vars.NET_SDK_VERSION }}" diff --git a/.github/workflows/build-status-check.yml b/.github/workflows/build-status-check.yml new file mode 100644 index 00000000..424c1da2 --- /dev/null +++ b/.github/workflows/build-status-check.yml @@ -0,0 +1,23 @@ +name: ✅Build Status Check +run-name: ✅Build Status Check ${{ github.base_ref == 'main' && '(Release Build)' || '(Debug Build)' }} + + +defaults: + run: + shell: pwsh + + +on: + workflow_dispatch: + pull_request: + branches: [main, preview] + + +jobs: + build_status_check: + name: ${{ vars.PROJECT_NAME }} Build Status Check + uses: KinsonDigital/Infrastructure/.github/workflows/build-csharp-project.yml@v9.1.0 + with: + project-name: "${{ vars.PROJECT_NAME }}" + build-config: Debug + net-sdk-version: "${{ vars.NET_SDK_VERSION }}" diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 00000000..387bb4a2 --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,79 @@ +name: 🚁Prepare Release + + +defaults: + run: + shell: pwsh + + +on: + workflow_dispatch: + inputs: + release-type: + description: The type of release. Choose 'Preview' or 'Production'. + required: true + type: choice + options: [Preview, Production] + release-version: + required: true + description: The version of the release to prepare. + type: string + + +jobs: + validate_inputs: + name: Validate Inputs + runs-on: ubuntu-latest + steps: + - name: Validating Inputs + run: | + $projectName = "${{ vars.PROJECT_NAME }}"; + $releaseType = "${{ inputs.release-type }}".ToLower(); + $releaseVersion = "${{ inputs.release-version }}"; + + if ($projectName -eq "") { + Write-Host "::error::The project name input cannot be empty."; + exit 1; + } + + + if ($releaseType -eq "") { + Write-Host "::error::The release type input cannot be empty."; + exit 1; + } + + + if ($releaseType -ne 'preview' -and $releaseType -ne 'roduction') { + Write-Host "::error::The release type input must be either 'Preview' or 'Production'."; + exit 1; + } + + + if ($releaseVersion -eq "") { + Write-Host "::error::The release version input cannot be empty."; + exit 1; + } + + + $prodVersionRegex = "v[0-9]+\.[0-9]+\.[0-9]+"; + $prevVersionRegex = "v[0-9]+\.[0-9]+\.[0-9]+-preview\.[0-9]+"; + + # Verify that the version has valid syntax + if (($version -match $prodVersionRegex) -or ($version -match $prevVersionRegex)) { + Write-Host "::notice::The version is valid."; + } else { + $versionSyntax = $releaseType == "production" ? "v#.#.#" : "v#.#.#-preview.#"; + Write-Host "::error::The version is not valid.\nThe version format is: '$versionSyntax"; + exit 1; + } + + + prepare_release: + name: Prepare ${{ inputs.release-type }} Release Of ${{ vars.PROJECT_NAME }} + uses: KinsonDigital/Infrastructure/.github/workflows/prepare-release.yml@v9.1.0 + with: + project-name: ${{ vars.PROJECT_NAME }} + release-type: ${{ inputs.release-type }} + release-version: ${{ inputs.release-version }} + secrets: + cicd-pat: ${{ secrets.CICD_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 33fe068d..060db08b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,5 @@ name: 🚀Release -run-name: ${{ vars.PROJECT_NAME }} ${{ inputs.release_type }} Release ${{ inputs.dry-run == true && '(Dry Run)' || '' }} +run-name: ${{ vars.PROJECT_NAME }} ${{ inputs.release-type }} Release ${{ inputs.dry-run == true && '(Dry Run)' || '' }} defaults: @@ -10,13 +10,11 @@ defaults: on: workflow_dispatch: inputs: - release_type: + release-type: description: The type of release. Choose 'Preview' or 'Production'. required: true type: choice - options: - - Preview - - Production + options: [Preview, Production] dry-run: description: Check to run the workflow without creating a release. required: false @@ -25,44 +23,24 @@ on: jobs: - determine_build_config: - name: Determine Build Configuration - runs-on: ubuntu-latest - outputs: - build-config: "${{ steps.get-build-config.outputs.build-config }}" - steps: - - name: Get Build Config - id: get-build-config - run: | - # If the branch that the workflow is running on is the required branch for the release, do a release build - if ( "${{ github.base_ref }}" -eq "main") { - "build-config=Release" >> $env:GITHUB_OUTPUT; - echo "Release build created."; - } else { # Any other branch than the release branch, do a debug build - "build-config=Debug" >> $env:GITHUB_OUTPUT; - echo "Debug build created."; - } - - run_release: - name: Performing ${{ inputs.release_type }} Release of ${{ vars.PROJECT_NAME }} ${{ inputs.dry-run == true && '(Dry Run)' || '' }} - needs: determine_build_config - uses: KinsonDigital/Infrastructure/.github/workflows/release.yml@v7.2.0 + name: Performing ${{ inputs.release-type }} Release of ${{ vars.PROJECT_NAME }} (${{ inputs.release-type == 'Production' && 'Release' || 'Debug' }}) + uses: KinsonDigital/Infrastructure/.github/workflows/dotnet-lib-release.yml@v9.1.0 with: project-name: "${{ vars.PROJECT_NAME}}" - release-type: "${{ inputs.release_type }}" + release-type: "${{ inputs.release-type }}" run-branch: "${{ github.ref_name }}" net-sdk-version: "${{ vars.NET_SDK_VERSION }}" relative-release-notes-dir-path: "${{ vars.RELATIVE_RELEASE_NOTES_DIR_PATH }}" release-notes-file-name-prefix: "${{ vars.RELEASE_NOTES_FILE_NAME_PREFIX }}" - build-config: "${{ needs.determine_build_config.outputs.build-config }}" + build-config: ${{ inputs.release-type == 'Production' && 'Release' || 'Debug' }} cicd-scripts-version: "${{ vars.CICD_SCRIPTS_VERSION }}" pr-include-notes-label: "${{ vars.PR_INCLUDE_NOTES_LABEL }}" send-release-tweet: ${{ vars.TWITTER_BROADCAST_ENABLED == 'true' }} dry-run: ${{ inputs.dry-run }} transpile-readme: true secrets: - cicd-rest-api: "${{ secrets.CICD_REST_API }}" + cicd-pat: "${{ secrets.CICD_TOKEN }}" nuget-org-api-key: "${{ secrets.NUGET_ORG_API_KEY }}" twitter-consumer-api-key: "${{ secrets.TWITTER_CONSUMER_API_KEY }}" twitter-consumer-api-secret: "${{ secrets.TWITTER_CONSUMER_API_SECRET }}" diff --git a/.github/workflows/sync-bot.yml b/.github/workflows/sync-bot.yml index 6f85e7ac..a7645801 100644 --- a/.github/workflows/sync-bot.yml +++ b/.github/workflows/sync-bot.yml @@ -13,7 +13,7 @@ on: jobs: sync_bot: - name: Sync Bot + name: Sync Bot Status Check if: ${{ !github.event.issue.pull_request }} runs-on: ubuntu-latest steps: @@ -30,19 +30,20 @@ jobs: $issueNumber = "${{ github.event.issue.number }}"; - echo "Project Name: ${{ vars.PROJECT_NAME }}"; - echo "Issue: $issueNumber"; + Write-Host "::notice:Project Name: ${{ vars.PROJECT_NAME }}"; + Write-Host "::notice:Issue: $issueNumber"; if ($manuallyExecuted -and $issueNumber -eq "0") { - echo "The issue or PR number must be a value greater than 0."; + Write-Host "::notice:The issue or PR number must be a value greater than 0."; exit 1; } <# Deno Args: - 1. Project Name - 2. Issue Number - 3. Event Type - set to issue event type - 4. GitHub token + 1. Organization name + 2. Project name + 3. Issue number + 4. Event Type - set to issue event type + 5. PAT #> deno run ` --allow-net ` @@ -50,4 +51,4 @@ jobs: "${{ vars.PROJECT_NAME }}" ` "$issueNumber" ` "issue" ` - "${{ secrets.CICD_REST_API }}"; + "${{ secrets.CICD_TOKEN }}"; diff --git a/.github/workflows/sync-issue-to-pr.yml b/.github/workflows/sync-issue-to-pr.yml index 1083c576..45356fb4 100644 --- a/.github/workflows/sync-issue-to-pr.yml +++ b/.github/workflows/sync-issue-to-pr.yml @@ -33,13 +33,21 @@ jobs: $prNumber = $eventName -eq "pull_request" ? "${{ github.event.number }}" : "${{ github.event.issue.number }}"; $command = $eventName -eq "issue_comment" ? "${{ github.event.comment.body }}" : "[initial-sync]"; - echo "Event Name: $eventName"; - echo "Organization Name: ${{ vars.ORGANIZATION_NAME }}"; - echo "Project Name: ${{ vars.PROJECT_NAME }}"; - echo "Requested By: ${{ github.event.sender.login }}"; - echo "PR Number: $prNumber"; - echo "Comment: $command"; - + Write-Host "::notice:Event Name: $eventName"; + Write-Host "::notice:Organization Name: ${{ vars.ORGANIZATION_NAME }}"; + Write-Host "::notice:Project Name: ${{ vars.PROJECT_NAME }}"; + Write-Host "::notice:Requested By: ${{ github.event.sender.login }}"; + Write-Host "::notice:PR Number: $prNumber"; + Write-Host "::notice:Comment: $command"; + + <# Deno Args: + 1. Organization name + 2. Project name + 3. Sync request by + 4. Pull request number + 5. Command - '[initial-sync]' or '[run-sync]' + 6. PAT + #> deno run ` --allow-net ` "$scriptUrl" ` @@ -48,4 +56,4 @@ jobs: "${{ github.event.sender.login }}" ` "$prNumber" ` "$command" ` - "${{ secrets.CICD_REST_API }}"; + "${{ secrets.CICD_TOKEN }}"; diff --git a/.github/workflows/sync-status-check.yml b/.github/workflows/sync-status-check.yml index 27b880f2..902cc551 100644 --- a/.github/workflows/sync-status-check.yml +++ b/.github/workflows/sync-status-check.yml @@ -27,25 +27,27 @@ jobs: $scriptUrl = "${{ vars.SCRIPT_BASE_URL }}/${{ vars.CICD_SCRIPTS_VERSION }}/${{ vars.SCRIPT_RELATIVE_DIR_PATH}}/sync-bot-status-check.ts"; $prNumber = "${{ github.event.number }}"; - echo "Project Name: ${{ vars.PROJECT_NAME }}"; - echo "PR Number: $prNumber"; - echo "Event Type: pr"; + Write-Host "::notice:Project Name: ${{ vars.PROJECT_NAME }}"; + Write-Host "::notice:PR Number: $prNumber"; + Write-Host "::notice:Event Type: pr"; if ($manuallyExecuted -and $prNumber -eq "0") { - echo "The issue or PR number must be a value greater than 0."; + Write-Host "::notice:The issue or PR number must be a value greater than 0."; exit 1; } <# Deno Args: - 1. Project Name - 2. PR Number - 3. Event Type - set to pull request event type - 4. GitHub token + 1. Organization name + 2. Project name + 3. Pull request number + 4. Event Type - set to pull request event type + 5. PAT #> deno run ` --allow-net ` "$scriptUrl" ` + "${{ vars.ORGANIZATION_NAME }}" ` "${{ vars.PROJECT_NAME }}" ` "$prNumber" ` "pr" ` - "${{ secrets.CICD_REST_API }}"; + "${{ secrets.CICD_TOKEN }}"; diff --git a/.github/workflows/unit-test-pr-status-check.yml b/.github/workflows/unit-test-pr-status-check.yml deleted file mode 100644 index d4432b65..00000000 --- a/.github/workflows/unit-test-pr-status-check.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: ✅Unit Testing Status Check -run-name: ✅Unit Testing Status Check ${{ github.base_ref == 'main' && '(Release Build)' || '(Debug Build)' }} - - -defaults: - run: - shell: pwsh - - -on: - workflow_dispatch: - pull_request: - branches: [main, preview] - - -jobs: - determine_build_config: - name: Determine Build Configuration - runs-on: ubuntu-latest - outputs: - build-config: ${{ steps.get-build-config.outputs.build-config }} - steps: - - name: Get Build Config - id: get-build-config - run: | - # If the destination branch that the pull request is merging into is the main, do a release build - if ("${{ github.base_ref }}" -eq "main") { - "build-config=Release" >> $env:GITHUB_OUTPUT; - } else { # Any other branch than main, do a debug build - "build-config=Debug" >> $env:GITHUB_OUTPUT; - } - - - run_tests: - name: Running ${{ vars.PROJECT_NAME }} Unit Tests - needs: determine_build_config - uses: KinsonDigital/Infrastructure/.github/workflows/run-csharp-tests.yml@v7.2.0 - with: - project-name: "${{ vars.PROJECT_NAME }}Tests" - build-config: ${{ needs.determine_build_config.outputs.build-config }} - net-sdk-version: "${{ vars.NET_SDK_VERSION }}" diff --git a/.github/workflows/unit-test-status-check.yml b/.github/workflows/unit-test-status-check.yml new file mode 100644 index 00000000..98022aff --- /dev/null +++ b/.github/workflows/unit-test-status-check.yml @@ -0,0 +1,23 @@ +name: ✅Unit Testing Status Check +run-name: ✅Unit Testing Status Check ${{ github.base_ref == 'main' && '(Release Build)' || '(Debug Build)' }} + + +defaults: + run: + shell: pwsh + + +on: + workflow_dispatch: + pull_request: + branches: [main, preview] + + +jobs: + run_tests: + name: ${{ vars.PROJECT_NAME }} Test Status Check + uses: KinsonDigital/Infrastructure/.github/workflows/run-csharp-tests.yml@v9.1.0 + with: + project-name: "${{ vars.PROJECT_NAME }}Tests" + build-config: Debug + net-sdk-version: "${{ vars.NET_SDK_VERSION }}" diff --git a/renovate.json b/renovate.json index 80bc8de1..c04d8456 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,5 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": ["github>KinsonDigital/.github//config/renovate-config.json"], - "baseBranches": ["master"] + "baseBranches": ["preview"] }