From 12d8b3cb26cb7ba7c0b75503ae0d2197c7424540 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 25 Apr 2024 16:20:50 +0100 Subject: [PATCH] Migrate to new version of workflow Closes #99 --- .cm/gitstream.cm | 17 +++++ .github/labels.yml | 11 ++- .github/workflows/blocked-issue.yml | 36 ++++++++++ .github/workflows/branch-develop.yml | 26 +++++++ .github/workflows/branch-feature.yml | 31 +++++++++ .github/workflows/branch-hotfix.yml | 58 ++++++++++++++++ .github/workflows/branch-master.yml | 53 +++++++++++++++ .github/workflows/branch-release.yml | 29 ++++++++ .github/workflows/codacy.yml | 61 ----------------- .../workflows/completed-feature-workflow.yml | 24 +++++++ .github/workflows/draft-new-release.yml | 67 +++++++++++++++++++ .github/workflows/gitstream.yml | 47 +++++++++++++ .../in-progress-feature-workflow.yml | 23 +++++++ .github/workflows/label-configurer.yml | 4 +- .github/workflows/new-issue-workflow.yml | 15 +++++ .github/workflows/stale-issues-prs.yml | 27 ++++++++ .github/workflows/step-build.yml | 58 ++++++++++++++++ .github/workflows/step-publish-package.yml | 37 ++++++++++ .github/workflows/step-publish.yml | 25 +++++++ .github/workflows/step-tag-release.yml | 20 ++++++ .github/workflows/step-version.yml | 66 ++++++++++++++++++ .github/workflows/test-dependabot.yml | 21 ++++++ .github/workflows/test-deploy.yml | 57 ---------------- CHANGELOG.md | 8 +++ NHSNumberGenerator.sln | 4 ++ build.cake | 59 ++++++++++++++++ semver.json | 6 ++ 27 files changed, 770 insertions(+), 120 deletions(-) create mode 100644 .cm/gitstream.cm create mode 100644 .github/workflows/blocked-issue.yml create mode 100644 .github/workflows/branch-develop.yml create mode 100644 .github/workflows/branch-feature.yml create mode 100644 .github/workflows/branch-hotfix.yml create mode 100644 .github/workflows/branch-master.yml create mode 100644 .github/workflows/branch-release.yml delete mode 100644 .github/workflows/codacy.yml create mode 100644 .github/workflows/completed-feature-workflow.yml create mode 100644 .github/workflows/draft-new-release.yml create mode 100644 .github/workflows/gitstream.yml create mode 100644 .github/workflows/in-progress-feature-workflow.yml create mode 100644 .github/workflows/new-issue-workflow.yml create mode 100644 .github/workflows/stale-issues-prs.yml create mode 100644 .github/workflows/step-build.yml create mode 100644 .github/workflows/step-publish-package.yml create mode 100644 .github/workflows/step-publish.yml create mode 100644 .github/workflows/step-tag-release.yml create mode 100644 .github/workflows/step-version.yml create mode 100644 .github/workflows/test-dependabot.yml delete mode 100644 .github/workflows/test-deploy.yml create mode 100644 CHANGELOG.md create mode 100644 build.cake create mode 100644 semver.json diff --git a/.cm/gitstream.cm b/.cm/gitstream.cm new file mode 100644 index 0000000..d25c2b8 --- /dev/null +++ b/.cm/gitstream.cm @@ -0,0 +1,17 @@ +# -*- mode: yaml -*- + +manifest: + version: 1.0 + +automations: + estimated_time_to_review: + if: + - true + run: + - action: add-label@v1 + args: + label: "{{ calc.etr }} min review" + color: {{ 'E94637' if (calc.etr >= 20) else ('FBBD10' if (calc.etr >= 5) else '36A853') }} + +calc: + etr: {{ branch | estimatedReviewTime }} \ No newline at end of file diff --git a/.github/labels.yml b/.github/labels.yml index b47b94b..f3cbca1 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -1,6 +1,9 @@ - name: "breaking change" color: "ff0205" description: "This change will require a major version bump" +- name: "blocked" + color: "e11d21" + description: "This issue is blocked by another issue" - name: "bug" color: "d73a4a" description: "Something isn't working" @@ -30,4 +33,10 @@ description: "An issue describing some techinal debt that needs to be addressed in the future" - name: "to do" color: "fbca04" - description: "Work that is yet to be started" \ No newline at end of file + description: "Work that is yet to be started" +- name: "awaiting feedback" + color: "fbca04" + description: "This issue is awaiting feedback from the reporter" +- name: "stale" + color: "eeeeee" + description: "This issue/PR has been inactive for too long" \ No newline at end of file diff --git a/.github/workflows/blocked-issue.yml b/.github/workflows/blocked-issue.yml new file mode 100644 index 0000000..aa565ce --- /dev/null +++ b/.github/workflows/blocked-issue.yml @@ -0,0 +1,36 @@ +name: Blocked Issue Labeler + +on: + issues: + types: + - opened + - edited + issue_comment: + types: + - created + - edited + +jobs: + add-blocked-label: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Add blocked label if issue is blocked + run: | + body=$BODY + comment=$COMMENT + issue_number=${{ github.event.issue.number }} + + # if body contains "blocked" or comment contains "blocked" + # add label "blocked" + + if [[ "${body,,}" == *"blocked"* ]] || [[ "${comment,,}" == *"blocked"* ]]; then + echo "Issue is blocked" + echo "Adding blocked label" + gh issue edit $issue_number --add-label blocked + fi + env: + BODY: ${{ github.event.issue.body }} + COMMENT: ${{ github.event.comment.body }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/branch-develop.yml b/.github/workflows/branch-develop.yml new file mode 100644 index 0000000..8e6a11e --- /dev/null +++ b/.github/workflows/branch-develop.yml @@ -0,0 +1,26 @@ +name: Deploy Develop Branch + +on: + push: + branches: + - develop + paths: + - 'src/**' + - 'test/**' + - '**.sln' + - '**.cake' + - '.github/workflows/branch-develop.yml' + - '.github/workflows/step-*.yml' + workflow_dispatch: + +jobs: + get-version: + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.base_ref }} diff --git a/.github/workflows/branch-feature.yml b/.github/workflows/branch-feature.yml new file mode 100644 index 0000000..4dafccf --- /dev/null +++ b/.github/workflows/branch-feature.yml @@ -0,0 +1,31 @@ +name: Deploy Feature Branch + +on: + pull_request: + types: [opened, synchronize] + branches: + - develop + paths: + - 'src/**' + - 'test/**' + - '**.sln' + - '**.cake' + - '.github/workflows/branch-feature.yml' + - '.github/workflows/step-*.yml' + workflow_dispatch: + +jobs: + get-version: + if: startsWith(github.head_ref, 'feature/') || github.head_ref == 'master' + uses: ./.github/workflows/step-version.yml + secrets: inherit + with: + is-pre-release: true + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.head_ref }} \ No newline at end of file diff --git a/.github/workflows/branch-hotfix.yml b/.github/workflows/branch-hotfix.yml new file mode 100644 index 0000000..22867a8 --- /dev/null +++ b/.github/workflows/branch-hotfix.yml @@ -0,0 +1,58 @@ +name: Deploy HotFix Branch + +on: + pull_request: + types: [opened, synchronize] + branches: + - master + workflow_dispatch: + +jobs: + get-version: + if: startsWith(github.head_ref, 'hotfix/') + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.head_ref }} + + update-metadata: + if: github.event.action == 'opened' + needs: [get-version] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: Increment Version + id: increment_version + run: | + echo "patch_version=$(($(cat semver.json | jq -r '.patch')+1))" > $GITHUB_OUTPUT + - name: Store New Version + uses: RadovanPelka/github-action-json@v1.0.1 + with: + path: semver.json + replaceWith: | + { + "major": "${{ needs.get-version.outputs.major }}", + "minor": "${{ needs.get-version.outputs.minor }}", + "patch": "${{ steps.increment_version.outputs.patch_version }}", + "build": "${{ github.run_number }}" + } + - name: Update changelog + uses: thomaseizinger/keep-a-changelog-new-release@1.3.0 + with: + tag: ${{ needs.get-version.outputs.major }}.${{ needs.get-version.outputs.minor }}.${{ steps.increment_version.outputs.patch_version }}.${{ github.run_number }} + - name: Commit Changes + run: | + git config --global user.name "GitHub Action Bot" + git config --global user.email "no-reply@after-life.co" + git add CHANGELOG.md semver.json + git commit --message "Bump Version to ${{ needs.get-version.outputs.major }}.${{ needs.get-version.outputs.minor }}.${{ steps.increment_version.outputs.patch_version }}.${{ github.run_number }}" + + - name: Push Version + run: git push origin ${{ github.head_ref }} \ No newline at end of file diff --git a/.github/workflows/branch-master.yml b/.github/workflows/branch-master.yml new file mode 100644 index 0000000..bc5d761 --- /dev/null +++ b/.github/workflows/branch-master.yml @@ -0,0 +1,53 @@ +name: Deploy Master Branch + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + get-version: + uses: ./.github/workflows/step-version.yml + with: + static-build: true + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.base_ref }} + + publish-to-nuget: + needs: [get-version,build] + uses: ./.github/workflows/step-publish.yml + secrets: inherit + with: + deploy-env: nuget + deploy-branch: ${{ github.base_ref }} + version: ${{ needs.get-version.outputs.version }} + + tag-release: + needs: [get-version,publish-to-nuget] + uses: ./.github/workflows/step-tag-release.yml + with: + version: ${{ needs.get-version.outputs.version }} + + merge-master-to-develop: + needs: [publish-to-nuget] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Create Pull Request + env: + GH_TOKEN: ${{ secrets.CREATE_PR_TOKEN }} + run: | + echo -e "This PR merges the master branch back into develop.\nThis happens to ensure that the updates that happened on the release branch, i.e. CHANGELOG updates are also present on the develop branch." > msg.txt + + export msg=$(cat msg.txt) ; gh pr create \ + --head master \ + --base develop \ + --title "Merge master into develop branch" \ + --body "$msg" \ No newline at end of file diff --git a/.github/workflows/branch-release.yml b/.github/workflows/branch-release.yml new file mode 100644 index 0000000..cb48bd9 --- /dev/null +++ b/.github/workflows/branch-release.yml @@ -0,0 +1,29 @@ +name: Deploy Release Branch + +on: + pull_request: + types: [opened, synchronize] + branches: + - master + - develop + paths: + - 'src/**' + - 'test/**' + - '**.sln' + - '**.cake' + - '.github/workflows/branch-release.yml' + - '.github/workflows/step-*.yml' + workflow_dispatch: + +jobs: + get-version: + if: startsWith(github.head_ref, 'release/') + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.head_ref }} diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml deleted file mode 100644 index b5745e9..0000000 --- a/.github/workflows/codacy.yml +++ /dev/null @@ -1,61 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# This workflow checks out code, performs a Codacy security scan -# and integrates the results with the -# GitHub Advanced Security code scanning feature. For more information on -# the Codacy security scan action usage and parameters, see -# https://github.com/codacy/codacy-analysis-cli-action. -# For more information on Codacy Analysis CLI in general, see -# https://github.com/codacy/codacy-analysis-cli. - -name: Codacy Security Scan - -on: - push: - branches: [ "develop" ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ "develop" ] - schedule: - - cron: '26 19 * * 2' - -permissions: - contents: read - -jobs: - codacy-security-scan: - permissions: - contents: read # for actions/checkout to fetch code - security-events: write # for github/codeql-action/upload-sarif to upload SARIF results - actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status - name: Codacy Security Scan - runs-on: ubuntu-latest - steps: - # Checkout the repository to the GitHub Actions runner - - name: Checkout code - uses: actions/checkout@v3 - - # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis - - name: Run Codacy Analysis CLI - uses: codacy/codacy-analysis-cli-action@33d455949345bddfdb845fba76b57b70cc83754b - with: - # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository - # You can also omit the token and run the tools that support default configurations - project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - verbose: true - output: results.sarif - format: sarif - # Adjust severity of non-security issues - gh-code-scanning-compat: true - # Force 0 exit code to allow SARIF file generation - # This will handover control about PR rejection to the GitHub side - max-allowed-issues: 2147483647 - - # Upload the SARIF file generated in the previous step - - name: Upload SARIF results file - uses: github/codeql-action/upload-sarif@v2 - with: - sarif_file: results.sarif diff --git a/.github/workflows/completed-feature-workflow.yml b/.github/workflows/completed-feature-workflow.yml new file mode 100644 index 0000000..84c3dc0 --- /dev/null +++ b/.github/workflows/completed-feature-workflow.yml @@ -0,0 +1,24 @@ +name: Completed Feature Workflow + +on: + pull_request: + branches: [ develop ] + types: [closed] + +jobs: + update-merged-issue-issues: + if: github.event.pull_request.merged_by != '' && github.actor != 'dependabot[bot]' && startsWith(github.head_ref, 'feature/issue-') + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Extract Issue Number + shell: bash + run: echo "##[set-output name=issue;]$(echo ${{ github.event.pull_request.head.ref }} | sed 's|[^0-9]||g')" + id: extract_issue + - name: Output Issue Number + run: echo "Issue Number- ${{ steps.extract_issue.outputs.issue }}" + - name: Update Labels + run: gh issue edit ${{ steps.extract_issue.outputs.issue }} --add-label "next release" --remove-label "in progress" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/draft-new-release.yml b/.github/workflows/draft-new-release.yml new file mode 100644 index 0000000..859b268 --- /dev/null +++ b/.github/workflows/draft-new-release.yml @@ -0,0 +1,67 @@ +name: "Draft new production release" + +on: + workflow_dispatch: + inputs: + major_version: + description: 'The major version you want to release.' + required: true + minor_version: + description: 'The minor version you want to release.' + required: true + patch_version: + description: 'The patch version you want to release.' + required: true + +jobs: + + draft-new-release: + name: "Draft a new release" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Create release branch + run: git checkout -b release/${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} + + - name: Update Version Number + uses: RadovanPelka/github-action-json@v1.0.1 + with: + path: semver.json + replaceWith: | + { + "major": "${{ github.event.inputs.major_version }}", + "minor": "${{ github.event.inputs.minor_version }}", + "patch": "${{ github.event.inputs.patch_version }}", + "build": "${{ github.run_number }}" + } + + - name: Update changelog + uses: thomaseizinger/keep-a-changelog-new-release@1.3.0 + with: + tag: ${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} + + - name: Commit changelog and manifest files + id: make-commit + run: | + git config --global user.name "GitHub Action Bot" + git config --global user.email "no-reply@after-life.co" + git add CHANGELOG.md semver.json + git commit --message "Prepare release ${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }}" + + echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + + - name: Push new branch + run: git push origin release/${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} + + - name: Create pull request + env: + GH_TOKEN: ${{ secrets.CREATE_PR_TOKEN }} + run: | + echo -e "Hi @${{ github.actor }}!\n\nThis PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}.\nI've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}.\n\nMerging this PR will create a GitHub release and upload any assets that are created as part of the release build." > msg.txt + + export msg=$(cat msg.txt) ; gh pr create \ + --head release/${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} \ + --base master \ + --title "Release version ${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }}" \ + --reviewer ${{ github.actor }} \ + --body "$msg" \ No newline at end of file diff --git a/.github/workflows/gitstream.yml b/.github/workflows/gitstream.yml new file mode 100644 index 0000000..7fa77fa --- /dev/null +++ b/.github/workflows/gitstream.yml @@ -0,0 +1,47 @@ +# Code generated by gitStream GitHub app - DO NOT EDIT + +name: gitStream workflow automation + +on: + workflow_dispatch: + inputs: + client_payload: + description: The Client payload + required: true + full_repository: + description: the repository name include the owner in `owner/repo_name` format + required: true + head_ref: + description: the head sha + required: true + base_ref: + description: the base ref + required: true + installation_id: + description: the installation id + required: false + resolver_url: + description: the resolver url to pass results to + required: true + resolver_token: + description: Optional resolver token for resolver service + required: false + default: '' + +jobs: + gitStream: + timeout-minutes: 5 + runs-on: ubuntu-latest + name: gitStream workflow automation + steps: + - name: Evaluate Rules + uses: linear-b/gitstream-github-action@v1 + id: rules-engine + with: + full_repository: ${{ github.event.inputs.full_repository }} + head_ref: ${{ github.event.inputs.head_ref }} + base_ref: ${{ github.event.inputs.base_ref }} + client_payload: ${{ github.event.inputs.client_payload }} + installation_id: ${{ github.event.inputs.installation_id }} + resolver_url: ${{ github.event.inputs.resolver_url }} + resolver_token: ${{ github.event.inputs.resolver_token }} diff --git a/.github/workflows/in-progress-feature-workflow.yml b/.github/workflows/in-progress-feature-workflow.yml new file mode 100644 index 0000000..b1b9126 --- /dev/null +++ b/.github/workflows/in-progress-feature-workflow.yml @@ -0,0 +1,23 @@ +name: In Progress Feature Workflow + +on: + push: + branches: + - feature/issue-* + +jobs: + update-in-progress-issues: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Extract Issue Number + shell: bash + run: echo "##[set-output name=issue;]$(echo ${GITHUB_REF#refs/heads/} | sed 's|[^0-9]||g')" + id: extract_issue + - name: Output Issue Number + run: echo "Issue Number- ${{ steps.extract_issue.outputs.issue }}" + - name: Update Labels + run: gh issue edit ${{ steps.extract_issue.outputs.issue }} --add-label "in progress" --remove-label "to do" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/label-configurer.yml b/.github/workflows/label-configurer.yml index 39016de..853345c 100644 --- a/.github/workflows/label-configurer.yml +++ b/.github/workflows/label-configurer.yml @@ -15,4 +15,6 @@ jobs: - name: Run Labeler uses: crazy-max/ghaction-github-labeler@v5 with: - github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + github-token: ${{ secrets.GITHUB_TOKEN }} + exclude: | + *min review \ No newline at end of file diff --git a/.github/workflows/new-issue-workflow.yml b/.github/workflows/new-issue-workflow.yml new file mode 100644 index 0000000..feba4ca --- /dev/null +++ b/.github/workflows/new-issue-workflow.yml @@ -0,0 +1,15 @@ +name: New Issue Workflow +on: + issues: + types: + - opened + +jobs: + update-new-issues: + runs-on: ubuntu-latest + steps: + - name: Initialise Labelling + run: gh issue edit $ISSUE --add-label "to do" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE: ${{ github.event.issue.html_url }} \ No newline at end of file diff --git a/.github/workflows/stale-issues-prs.yml b/.github/workflows/stale-issues-prs.yml new file mode 100644 index 0000000..d44b1eb --- /dev/null +++ b/.github/workflows/stale-issues-prs.yml @@ -0,0 +1,27 @@ +name: Close inactive issues and PRs +on: + schedule: + - cron: "30 1 * * *" + workflow_dispatch: + +jobs: + close-issues: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/stale@v9 + with: + days-before-issue-stale: 30 + days-before-issue-close: 14 + stale-issue-label: "stale" + stale-pr-label: "stale" + stale-issue-message: "This issue is stale because it has been open for 30 days with no activity." + close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." + stale-pr-message: "This PR is stale because it has been open for 30 days with no activity." + close-pr-message: "This PR was closed because it has been inactive for 14 days since being marked as stale." + days-before-pr-stale: 30 + days-before-pr-close: 14 + only-labels: "awaiting feedback" + repo-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/step-build.yml b/.github/workflows/step-build.yml new file mode 100644 index 0000000..e8c7649 --- /dev/null +++ b/.github/workflows/step-build.yml @@ -0,0 +1,58 @@ +on: + workflow_call: + inputs: + version: + description: 'The version number to use for the build' + required: true + type: string + checkout-ref: + description: 'The commit SHA to checkout' + required: true + type: string + +jobs: + build-libraries: + runs-on: ubuntu-latest + steps: + - name: Log Branch + run: | + echo "Branch: ${{ inputs.checkout-ref }}" + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ inputs.checkout-ref }} + - name: Setup .NET Core + uses: actions/setup-dotnet@v4.0.0 + with: + dotnet-version: 8.0.x + - name: Restore + uses: cake-build/cake-action@v2 + with: + target: Restore + - name: Build + uses: cake-build/cake-action@v2 + with: + target: Build + arguments: | + versionNumber: ${{inputs.version}} + - name: Run tests + uses: cake-build/cake-action@v2 + with: + target: Test + - name: Publish Unit Test Results + if: ${{ github.actor != 'dependabot[bot]' }} + uses: EnricoMi/publish-unit-test-result-action/composite@v2 + with: + files: "**/TestResults/*.xml" + - name: Build NuGet Package + uses: cake-build/cake-action@v2 + with: + target: Pack + arguments: | + versionNumber: ${{inputs.version}} + - name: Upload Package + if: ${{ github.actor != 'dependabot[bot]' }} + uses: actions/upload-artifact@v4 + with: + name: NHSNumberGenerator + path: ./src/NHSNumberGenerator/bin/Release/*.nupkg \ No newline at end of file diff --git a/.github/workflows/step-publish-package.yml b/.github/workflows/step-publish-package.yml new file mode 100644 index 0000000..ea90790 --- /dev/null +++ b/.github/workflows/step-publish-package.yml @@ -0,0 +1,37 @@ +on: + workflow_call: + inputs: + deploy-env: + required: true + description: 'Environment to deploy to' + type: string + deploy-branch: + required: true + description: 'Branch to deploy' + type: string + version: + description: 'The version number to use for the build' + required: true + type: string + package-name: + description: 'The name of the package to push' + required: true + type: string + +jobs: + push-package: + runs-on: ubuntu-latest + environment: ${{ inputs.deploy-env }} + steps: + - name: Download Package + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.package-name }} + path: ./src/NHSNumberGenerator/bin/Release + - name: Setup .NET Core + uses: actions/setup-dotnet@v4.0.0 + with: + dotnet-version: 8.0.x + - name: Push package to NuGet + run: | + dotnet nuget push $(find ./src/NHSNumberGenerator/bin/Release/*.nupkg) --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/.github/workflows/step-publish.yml b/.github/workflows/step-publish.yml new file mode 100644 index 0000000..679fbad --- /dev/null +++ b/.github/workflows/step-publish.yml @@ -0,0 +1,25 @@ +on: + workflow_call: + inputs: + deploy-env: + required: true + description: 'Environment to deploy to' + type: string + deploy-branch: + required: true + description: 'Branch to deploy' + type: string + version: + description: 'The version number to use for the build' + required: true + type: string + +jobs: + publish-package: + uses: ./.github/workflows/step-publish-package.yml + secrets: inherit + with: + deploy-env: ${{ inputs.deploy-env }} + deploy-branch: ${{ inputs.deploy-branch }} + version: ${{ inputs.version }} + package-name: NHSNumberGenerator \ No newline at end of file diff --git a/.github/workflows/step-tag-release.yml b/.github/workflows/step-tag-release.yml new file mode 100644 index 0000000..6f9b247 --- /dev/null +++ b/.github/workflows/step-tag-release.yml @@ -0,0 +1,20 @@ +on: + workflow_call: + inputs: + version: + required: true + description: 'Version to deploy' + type: string + +jobs: + tag: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create tag + run: | + git config --global user.name "GitHub Action Bot" + git config --global user.email "no-reply@after-life.co" + git tag -a ${{ inputs.version }} -m "Version ${{ inputs.version }} created via GitHub Actions" + git push origin ${{ inputs.version }} \ No newline at end of file diff --git a/.github/workflows/step-version.yml b/.github/workflows/step-version.yml new file mode 100644 index 0000000..3e4de85 --- /dev/null +++ b/.github/workflows/step-version.yml @@ -0,0 +1,66 @@ +on: + workflow_call: + inputs: + static-build: + description: 'Should the build number come from the semver.json file?' + type: boolean + required: false + default: false + is-pre-release: + description: 'Is this a pre-release?' + type: boolean + required: false + default: false + outputs: + version: + description: 'The version of the app' + value: ${{ jobs.version-number.outputs.version }} + major: + description: 'The major version of the app' + value: ${{ jobs.version-number.outputs.major }} + minor: + description: 'The minor version of the app' + value: ${{ jobs.version-number.outputs.minor }} + patch: + description: 'The patch version of the app' + value: ${{ jobs.version-number.outputs.patch }} + build: + description: 'The patch version of the app' + value: ${{ jobs.version-number.outputs.build }} + +jobs: + version-number: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.set-version.outputs.version }} + major: ${{ steps.set-version.outputs.major }} + minor: ${{ steps.set-version.outputs.minor }} + patch: ${{ steps.set-version.outputs.patch }} + build: ${{ steps.set-version.outputs.build }} + steps: + - name: Get Code + uses: actions/checkout@v4 + - name: Get Version + id: get-version + uses: RadovanPelka/github-action-json@v1.0.1 + with: + path: 'semver.json' + - id: set-version + run: | + echo "major=${{ steps.get-version.outputs.major }}" >> $GITHUB_OUTPUT + echo "minor=${{ steps.get-version.outputs.minor }}" >> $GITHUB_OUTPUT + echo "patch=${{ steps.get-version.outputs.patch }}" >> $GITHUB_OUTPUT + + suffix="" + + if [ "${{ inputs.is-pre-release }}" == true ]; then + suffix="-alpha" + fi + + if [ "${{ inputs.static-build }}" == true ]; then + echo "version=${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }}.${{ steps.get-version.outputs.patch }}.${{ steps.get-version.outputs.build }}${suffix}" >> $GITHUB_OUTPUT + echo "build=${{ steps.get-version.outputs.build }}" >> $GITHUB_OUTPUT + else + echo "version=${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }}.${{ steps.get-version.outputs.patch }}.${{ github.run_number }}${suffix}" >> $GITHUB_OUTPUT + echo "build=${{ github.run_number }}" >> $GITHUB_OUTPUT + fi \ No newline at end of file diff --git a/.github/workflows/test-dependabot.yml b/.github/workflows/test-dependabot.yml new file mode 100644 index 0000000..24fbaa0 --- /dev/null +++ b/.github/workflows/test-dependabot.yml @@ -0,0 +1,21 @@ +name: Test Dependabot PRs + +on: + pull_request_target: + types: [opened, synchronize] + branches: + - develop + workflow_dispatch: + +jobs: + get-version: + if: ${{ github.actor == 'dependabot[bot]' }} + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.event.pull_request.head.sha }} \ No newline at end of file diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml deleted file mode 100644 index aa7ecde..0000000 --- a/.github/workflows/test-deploy.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Test and Deploy Library - -env: - VERSION_NUMBER: 1.0.2 - NUGET_KEY: ${{ secrets.NUGET_API_KEY }} - DOTNET_MAJOR_VERSION: 8 - -on: - push: - branches: - - master - - develop - - release/* - pull_request: - branches: [ develop ] - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: ${{ env.DOTNET_MAJOR_VERSION }}.0.x - - name: Install dependencies - run: dotnet restore - - name: Run tests - run: dotnet test --logger "xunit;LogFileName=results.xml" - - name: Publish Unit Test Results - uses: EnricoMi/publish-unit-test-result-action/composite@v2 - if: ${{ github.actor != 'dependabot[bot]' }} - with: - xunit_files: "**/TestResults/*.xml" - - publish: - runs-on: ubuntu-latest - needs: [test] - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} - - steps: - - uses: actions/checkout@v3 - - name: Setup .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: ${{ env.DOTNET_MAJOR_VERSION }}.0.x - - name: Output Version Number - run: echo "Version-$VERSION_NUMBER.$GITHUB_RUN_NUMBER" - - name: Install dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: Package - run: dotnet pack ./src/NHSNumberGenerator/NHSNumberGenerator.csproj -c Release /P:PackageVersion=$VERSION_NUMBER.$GITHUB_RUN_NUMBER - - name: Publish - run: nuget push ./src/NHSNumberGenerator/bin/Release/NHSNumberGenerator.$VERSION_NUMBER.$GITHUB_RUN_NUMBER.nupkg -ApiKey $NUGET_KEY -NonInteractive -Source https://www.nuget.org/api/v2/package diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..715c79e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] \ No newline at end of file diff --git a/NHSNumberGenerator.sln b/NHSNumberGenerator.sln index ca5e1bc..2c9e26f 100644 --- a/NHSNumberGenerator.sln +++ b/NHSNumberGenerator.sln @@ -18,6 +18,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitmessage = .gitmessage LICENSE.txt = LICENSE.txt README.md = README.md + build.cake = build.cake + CHANGELOG.md = CHANGELOG.md + semver.json = semver.json + .cm\gitstream.cm = .cm\gitstream.cm EndProjectSection EndProject Global diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..ea9ef99 --- /dev/null +++ b/build.cake @@ -0,0 +1,59 @@ +var target = Argument("target", "Test"); +var configuration = Argument("configuration", "Release"); +var versionNumber = Argument("versionNumber", "0.1.0"); +var projectName = "NHSNumberGenerator"; +var solutionFolder = "./"; + +Task("Clean") + .Does(() => + { + // Clean solution + DotNetClean(solutionFolder); + }); + +Task("Restore") + .Does(() => + { + // Restore NuGet packages + DotNetRestore(solutionFolder); + }); + +Task("Build") + .Does(() => + { + // Build solution + DotNetBuild(solutionFolder, new DotNetBuildSettings + { + NoRestore = true, + Configuration = configuration, + ArgumentCustomization = args => args.Append("/p:Version=" + versionNumber) + }); + }); + +Task("Test") + .Does(() => + { + // Run tests + DotNetTest(solutionFolder, new DotNetTestSettings + { + NoRestore = true, + NoBuild = true, + Configuration = configuration, + Loggers = new string[] { "junit;LogFileName=results.xml" } + }); + }); + +Task("Pack") + .Does(() => + { + // Publish solution + DotNetPack(solutionFolder, new DotNetPackSettings + { + NoRestore = true, + NoBuild = true, + Configuration = configuration, + ArgumentCustomization = args => args.Append("/p:PackageVersion=" + versionNumber) + }); + }); + +RunTarget(target); \ No newline at end of file diff --git a/semver.json b/semver.json new file mode 100644 index 0000000..6f9918b --- /dev/null +++ b/semver.json @@ -0,0 +1,6 @@ +{ + "major": "1", + "minor": "0", + "patch": "2", + "build": "94" +} \ No newline at end of file