From 23cbf84259de4e27198647b38568decf807e9595 Mon Sep 17 00:00:00 2001 From: Phil Asmar Date: Fri, 18 Oct 2024 15:59:38 -0400 Subject: [PATCH 1/2] ci: add support for automated versioning and changelog creation --- .autover/autover.json | 11 ++ .github/workflows/create-release-pr.yml | 101 +++++++++++++++++ .github/workflows/sync-main-dev.yml | 137 ++++++++++++++++++++++++ .gitignore | 6 +- CHANGELOG.md | 15 ++- CONTRIBUTING.md | 43 ++++++++ 6 files changed, 307 insertions(+), 6 deletions(-) create mode 100644 .autover/autover.json create mode 100644 .github/workflows/create-release-pr.yml create mode 100644 .github/workflows/sync-main-dev.yml diff --git a/.autover/autover.json b/.autover/autover.json new file mode 100644 index 0000000..3af140b --- /dev/null +++ b/.autover/autover.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.AspNetCore.Identity.Cognito", + "Path": "src/Amazon.AspNetCore.Identity.Cognito/Amazon.AspNetCore.Identity.Cognito.csproj" + } + ], + "UseCommitsForChangelog": false, + "DefaultIncrementType": "Patch", + "ChangeFilesDetermineIncrementType": true +} \ No newline at end of file diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml new file mode 100644 index 0000000..2591e5f --- /dev/null +++ b/.github/workflows/create-release-pr.yml @@ -0,0 +1,101 @@ +# This GitHub Workflow will create a new release branch that contains the updated C# project versions and changelog. +# The workflow will also create a PR that targets `dev` from the release branch. +name: Create Release PR + +# This workflow is manually triggered when in preparation for a release. The workflow should be dispatched from the `dev` branch. +on: + workflow_dispatch: + inputs: + OVERRIDE_VERSION: + description: "Override Version" + type: string + required: false + +permissions: + id-token: write + +jobs: + release-pr: + name: Release PR + runs-on: ubuntu-latest + + env: + INPUT_OVERRIDE_VERSION: ${{ github.event.inputs.OVERRIDE_VERSION }} + + steps: + # Assume an AWS Role that provides access to the Access Token + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 #v4 + with: + role-to-assume: ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_ROLE_ARN }} + aws-region: us-west-2 + # Retrieve the Access Token from Secrets Manager + - name: Retrieve secret from AWS Secrets Manager + uses: aws-actions/aws-secretsmanager-get-secrets@v2 + with: + secret-ids: | + AWS_SECRET, ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_NAME }} + parse-json-secrets: true + # Checkout a full clone of the repo + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' + token: ${{ env.AWS_SECRET_TOKEN }} + # Install .NET8 which is needed for AutoVer + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + # Install AutoVer to automate versioning and changelog creation + - name: Install AutoVer + run: dotnet tool install --global AutoVer --version 0.0.21 + # Set up a git user to be able to run git commands later on + - name: Setup Git User + run: | + git config --global user.email "github-aws-sdk-dotnet-automation@amazon.com" + git config --global user.name "aws-sdk-dotnet-automation" + # Create the release branch which will contain the version changes and updated changelog + - name: Create Release Branch + id: create-release-branch + run: | + branch=releases/next-release + git checkout -b $branch + echo "BRANCH=$branch" >> $GITHUB_OUTPUT + # Update the version of projects based on the change files + - name: Increment Version + run: autover version + if: env.INPUT_OVERRIDE_VERSION == '' + # Update the version of projects based on the override version + - name: Increment Version + run: autover version --use-version "$INPUT_OVERRIDE_VERSION" + if: env.INPUT_OVERRIDE_VERSION != '' + # Update the changelog based on the change files + - name: Update Changelog + run: autover changelog + # Push the release branch up as well as the created tag + - name: Push Changes + run: | + branch=${{ steps.create-release-branch.outputs.BRANCH }} + git push origin $branch + git push origin $branch --tags + # Get the release name that will be used to create a PR + - name: Read Release Name + id: read-release-name + run: | + version=$(autover changelog --release-name) + echo "VERSION=$version" >> $GITHUB_OUTPUT + # Get the changelog that will be used to create a PR + - name: Read Changelog + id: read-changelog + run: | + changelog=$(autover changelog --output-to-console) + echo "CHANGELOG<> "$GITHUB_OUTPUT" + # Create the Release PR and label it + - name: Create Pull Request + env: + GITHUB_TOKEN: ${{ env.AWS_SECRET_TOKEN }} + run: | + pr_url="$(gh pr create --title "${{ steps.read-release-name.outputs.VERSION }}" --body "${{ steps.read-changelog.outputs.CHANGELOG }}" --base dev --head ${{ steps.create-release-branch.outputs.BRANCH }})" + gh label create "Release PR" --description "A Release PR that includes versioning and changelog changes" -c "#FF0000" -f + gh pr edit $pr_url --add-label "Release PR" \ No newline at end of file diff --git a/.github/workflows/sync-main-dev.yml b/.github/workflows/sync-main-dev.yml new file mode 100644 index 0000000..e7e4a84 --- /dev/null +++ b/.github/workflows/sync-main-dev.yml @@ -0,0 +1,137 @@ +# This GitHub Workflow is designed to run automatically after the Release PR, which was created by the `Create Release PR` workflow, is closed. +# This workflow has 2 jobs. One will run if the `Release PR` is successfully merged, indicating that a release should go out. +# The other will run if the `Release PR` was closed and a release is not intended to go out. +name: Sync 'dev' and 'master' + +# The workflow will automatically be triggered when any PR is closed. +on: + pull_request: + types: [closed] + +permissions: + contents: write + id-token: write + +jobs: + # This job will check if the PR was successfully merged, it's source branch is `releases/next-release` and target branch is `dev`. + # This indicates that the merged PR was the `Release PR`. + # This job will synchronize `dev` and `master`, create a GitHub Release and delete the `releases/next-release` branch. + sync-dev-and-main: + name: Sync dev and master + if: | + github.event.pull_request.merged == true && + github.event.pull_request.head.ref == 'releases/next-release' && + github.event.pull_request.base.ref == 'dev' + runs-on: ubuntu-latest + steps: + # Assume an AWS Role that provides access to the Access Token + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 #v4 + with: + role-to-assume: ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_ROLE_ARN }} + aws-region: us-west-2 + # Retrieve the Access Token from Secrets Manager + - name: Retrieve secret from AWS Secrets Manager + uses: aws-actions/aws-secretsmanager-get-secrets@v2 + with: + secret-ids: | + AWS_SECRET, ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_NAME }} + parse-json-secrets: true + # Checkout a full clone of the repo + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: dev + fetch-depth: 0 + token: ${{ env.AWS_SECRET_TOKEN }} + # Install .NET8 which is needed for AutoVer + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + # Install AutoVer which is needed to retrieve information about the current release. + - name: Install AutoVer + run: dotnet tool install --global AutoVer --version 0.0.21 + # Set up a git user to be able to run git commands later on + - name: Setup Git User + run: | + git config --global user.email "github-aws-sdk-dotnet-automation@amazon.com" + git config --global user.name "aws-sdk-dotnet-automation" + # Retrieve the release name which is needed for the GitHub Release + - name: Read Release Name + id: read-release-name + run: | + version=$(autover changelog --release-name) + echo "VERSION=$version" >> $GITHUB_OUTPUT + # Retrieve the tag name which is needed for the GitHub Release + - name: Read Tag Name + id: read-tag-name + run: | + tag=$(autover changelog --tag-name) + echo "TAG=$tag" >> $GITHUB_OUTPUT + # Retrieve the changelog which is needed for the GitHub Release + - name: Read Changelog + id: read-changelog + run: | + changelog=$(autover changelog --output-to-console) + echo "CHANGELOG<> "$GITHUB_OUTPUT" + # Merge dev into master in order to synchronize the 2 branches + - name: Merge dev to master + run: | + git fetch origin + git checkout master + git merge dev + git push origin master + # Create the GitHub Release + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ env.AWS_SECRET_TOKEN }} + run: | + gh release create "${{ steps.read-tag-name.outputs.TAG }}" --title "${{ steps.read-release-name.outputs.VERSION }}" --notes "${{ steps.read-changelog.outputs.CHANGELOG }}" + # Delete the `releases/next-release` branch + - name: Clean up + run: | + git fetch origin + git push origin --delete releases/next-release + # This job will check if the PR was closed, it's source branch is `releases/next-release` and target branch is `dev`. + # This indicates that the closed PR was the `Release PR`. + # This job will delete the tag created by AutoVer and the release branch. + clean-up-closed-release: + name: Clean up closed release + if: | + github.event.pull_request.merged == false && + github.event.pull_request.head.ref == 'releases/next-release' && + github.event.pull_request.base.ref == 'dev' + runs-on: ubuntu-latest + steps: + # Checkout a full clone of the repo + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: releases/next-release + fetch-depth: 0 + # Install .NET8 which is needed for AutoVer + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + # Install AutoVer which is needed to retrieve information about the current release. + - name: Install AutoVer + run: dotnet tool install --global AutoVer --version 0.0.21 + # Set up a git user to be able to run git commands later on + - name: Setup Git User + run: | + git config --global user.email "github-aws-sdk-dotnet-automation@amazon.com" + git config --global user.name "aws-sdk-dotnet-automation" + # Retrieve the tag name to be deleted + - name: Read Tag Name + id: read-tag-name + run: | + tag=$(autover changelog --tag-name) + echo "TAG=$tag" >> $GITHUB_OUTPUT + # Delete the tag created by AutoVer and the release branch + - name: Clean up + run: | + git fetch origin + git push --delete origin ${{ steps.read-tag-name.outputs.TAG }} + git push origin --delete releases/next-release \ No newline at end of file diff --git a/.gitignore b/.gitignore index ecf9385..74a6106 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,8 @@ **/project.lock.json **/*.nuspec -packages \ No newline at end of file +packages + +# JetBrains Rider +.idea/ +*.sln.iml \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 24b2934..281edb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,15 @@ -### 3.0.2 (2024-04-20) +## Release 2024-04-20 + +### Amazon.AspNetCore.Identity.Cognito (3.0.2) * Update User-Agent string -### 3.0.1 (2021-07-06) +## Release 2021-07-06 + +### Amazon.AspNetCore.Identity.Cognito (3.0.1) * Pull request [#223](https://github.com/aws/aws-aspnet-cognito-identity-provider/pull/223) Fix UTC time conversion. Thanks [Joseph Fergusson](https://github.com/PhonicCanine) -### 3.0.0 (2021-07-06) -* Add target framework .NET Core 3.1 -* Remove target framework .NET Core 3.0 +## Release 2021-07-06 +### Amazon.AspNetCore.Identity.Cognito (3.0.0) +* Add target framework .NET Core 3.1 +* Remove target framework .NET Core 3.0 \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 27c6d1b..a3d766f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,6 +39,49 @@ To send us a pull request, please: GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). +## Adding a `change file` to your contribution branch + +Each contribution branch should include a `change file` that contains a changelog message for each project that has been updated, as well as the type of increment to perform for those changes when versioning the project. + +A `change file` looks like the following example: +```json +{ + "Projects": [ + { + "Name": "Amazon.AspNetCore.Identity.Cognito", + "Type": "Patch", + "ChangelogMessages": [ + "Fixed an issue causing a failure somewhere" + ] + } + ] +} +``` +The `change file` lists all the modified projects, the changelog message for each project as well as the increment type. + +These files are located in the repo at .autover/changes/ + +You can use the `AutoVer` tool to create the change file. You can install it using the following command: +``` +dotnet tool install -g AutoVer +``` + +You can create the `change file` using the following command: +``` +autover change --project-name "Amazon.AspNetCore.Identity.Cognito" -m "Fixed an issue causing a failure somewhere +``` +Note: Make sure to run the command from the root of the repository. + +You can update the command to specify which project you are updating. +The available projects are: +* Amazon.AspNetCore.Identity.Cognito + +The possible increment types are: +* Patch +* Minor +* Major + +Note: You do not need to create a new `change file` for every changelog message or project within your branch. You can create one `change file` that contains all the modified projects and the changelog messages. ## Finding contributions to work on Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/aws-aspnet-cognito-identity-provider/labels/help%20wanted) issues is a great place to start. From 4183a8c1430c55509bc0524131d2472edc69aa95 Mon Sep 17 00:00:00 2001 From: Phil Asmar Date: Mon, 21 Oct 2024 14:27:36 -0400 Subject: [PATCH 2/2] ci: onboard the repo to the testing infra --- .github/workflows/aws-ci.yml | 46 +++++++++++++++++++ buildtools/ci.buildspec.yml | 15 ++++++ ...n.AspNetCore.Identity.Cognito.Tests.csproj | 1 + 3 files changed, 62 insertions(+) create mode 100644 .github/workflows/aws-ci.yml create mode 100644 buildtools/ci.buildspec.yml diff --git a/.github/workflows/aws-ci.yml b/.github/workflows/aws-ci.yml new file mode 100644 index 0000000..f35e624 --- /dev/null +++ b/.github/workflows/aws-ci.yml @@ -0,0 +1,46 @@ +name: AWS CI + +on: + workflow_dispatch: + pull_request: + branches: + - master + - dev + - 'feature/**' + +permissions: + id-token: write + +jobs: + run-ci: + runs-on: ubuntu-latest + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 #v4 + with: + role-to-assume: ${{ secrets.CI_MAIN_TESTING_ACCOUNT_ROLE_ARN }} + role-duration-seconds: 7200 + aws-region: us-west-2 + - name: Invoke Load Balancer Lambda + id: lambda + shell: pwsh + run: | + aws lambda invoke response.json --function-name "${{ secrets.CI_TESTING_LOAD_BALANCER_LAMBDA_NAME }}" --cli-binary-format raw-in-base64-out --payload '{"Roles": "${{ secrets.CI_TEST_RUNNER_ACCOUNT_ROLES }}", "ProjectName": "${{ secrets.CI_TESTING_CODE_BUILD_PROJECT_NAME }}", "Branch": "${{ github.sha }}"}' + $roleArn=$(cat ./response.json) + "roleArn=$($roleArn -replace '"', '')" >> $env:GITHUB_OUTPUT + - name: Configure Test Runner Credentials + uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 #v4 + with: + role-to-assume: ${{ steps.lambda.outputs.roleArn }} + role-duration-seconds: 7200 + aws-region: us-west-2 + - name: Run Tests on AWS + id: codebuild + uses: aws-actions/aws-codebuild-run-build@v1 + with: + project-name: ${{ secrets.CI_TESTING_CODE_BUILD_PROJECT_NAME }} + - name: CodeBuild Link + shell: pwsh + run: | + $buildId = "${{ steps.codebuild.outputs.aws-build-id }}" + echo $buildId \ No newline at end of file diff --git a/buildtools/ci.buildspec.yml b/buildtools/ci.buildspec.yml new file mode 100644 index 0000000..64a94b1 --- /dev/null +++ b/buildtools/ci.buildspec.yml @@ -0,0 +1,15 @@ +version: 0.2 + +phases: + install: + runtime-versions: + dotnet: 8.x + build: + commands: + - dotnet test test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj -c Release --logger trx --results-directory ./testresults +reports: + aws-ssm-data-protection-provider-for-aspnet-tests: + file-format: VisualStudioTrx + files: + - '**/*' + base-directory: './testresults' \ No newline at end of file diff --git a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj index 3c4a95a..0eb9be0 100644 --- a/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj +++ b/test/unit/Amazon.AspNetCore.Identity.Cognito.Tests/Amazon.AspNetCore.Identity.Cognito.Tests.csproj @@ -3,6 +3,7 @@ Library netcoreapp3.1 + Major