diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 8ce7fe9..1980c4e 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -16,7 +16,10 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: 6.0.100 - - name: Run docker-compose - run: docker-compose up -d + # `docker-compose` (Compose v1) is no longer installed on GitHub-hosted + # runners; v2 is a docker subcommand. --wait blocks until the localstack + # healthcheck passes, instead of racing it from the test step. + - name: Run docker compose + run: docker compose up -d --wait - name: Run Integration Tests run: dotnet test ./test/SqsPoller.Extensions.Publisher.Tests.Integration/SqsPoller.Extensions.Publisher.Tests.Integration.csproj \ No newline at end of file diff --git a/.github/workflows/publish-codeartifact.yml b/.github/workflows/publish-codeartifact.yml new file mode 100644 index 0000000..cffb574 --- /dev/null +++ b/.github/workflows/publish-codeartifact.yml @@ -0,0 +1,100 @@ +name: Publish NuGet package to CodeArtifact + +# Publishes on an annotated version tag, not on every push to master. The package +# version comes from the csproj, so a push-triggered publish would fail on any +# commit that does not bump it. Tagging is already how this repository is versioned. +on: + push: + tags: + - 'v*' + workflow_dispatch: + +permissions: + id-token: write + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +jobs: + publish: + # GitHub-hosted: the self-hosted `gha-runner-scale-set` label is not available + # to this repository, so jobs targeting it stay queued forever. OIDC works the + # same on hosted runners. + runs-on: ubuntu-latest + env: + CODEARTIFACT_DOMAIN: "idt" + CODEARTIFACT_DOMAIN_OWNER: "416223954868" + CODEARTIFACT_REPO: "team_caf-nuget" + CODEARTIFACT_TOOL: "dotnet" + + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::101838717447:role/github-actions-role + aws-region: ${{ secrets.AWS_REGION || 'us-east-1' }} + + - name: Log in to CodeArtifact + run: | + aws codeartifact login --tool ${{ env.CODEARTIFACT_TOOL }} \ + --domain ${{ env.CODEARTIFACT_DOMAIN }} \ + --domain-owner ${{ env.CODEARTIFACT_DOMAIN_OWNER }} \ + --repository ${{ env.CODEARTIFACT_REPO }} + + # The tag is the source of truth for the released version: `-p:Version` overrides + # the csproj, so v2.1.0 always produces 2.1.0. Without this the csproj decides, + # and tagging without bumping it republishes the old version, which + # --skip-duplicate then turns into a silently green no-op. + # + # workflow_dispatch runs from a branch, where GITHUB_REF_NAME is not a version; + # there the csproj value is used unchanged. + # + # -p:GeneratePackageOnBuild=false: both csproj set GeneratePackageOnBuild=true, + # which wires packing into build. On SDK 10 `dotnet pack` then does not rebuild + # and fails with NU5026 (dll not found on disk); SDK 8 tolerated it. + # + # The two library projects are packed explicitly. `dotnet pack` on the solution + # also packs sample/SqsPoller.Sample.Publisher and sample/SqsPoller.Sample.Subscriber, + # which are not products and would be pushed to the feed as 1.0.0. + - name: Pack + run: | + VERSION_ARG="" + if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then + VERSION="${GITHUB_REF_NAME#v}" + if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then + echo "::error::Tag '$GITHUB_REF_NAME' does not yield a valid version ('$VERSION'). Expected vMAJOR.MINOR.PATCH[-suffix]." + exit 1 + fi + VERSION_ARG="-p:Version=$VERSION" + echo "Releasing version $VERSION from tag $GITHUB_REF_NAME" + else + echo "Not a tag ref; using the version declared in the csproj." + fi + + dotnet pack src/SqsPoller/SqsPoller.csproj \ + -c Release -o ./artifacts -p:GeneratePackageOnBuild=false $VERSION_ARG + dotnet pack src/SqsPoller.Extensions.Publisher/SqsPoller.Extensions.Publisher.csproj \ + -c Release -o ./artifacts -p:GeneratePackageOnBuild=false $VERSION_ARG + + # --skip-duplicate makes a re-run of the same tag a no-op instead of a + # failure. CodeArtifact rejects overwriting an existing version. + - name: Push to CodeArtifact + run: | + dotnet nuget push "./artifacts/*.nupkg" \ + --source ${{ env.CODEARTIFACT_DOMAIN }}/${{ env.CODEARTIFACT_REPO }} \ + --api-key unused \ + --skip-duplicate + + - name: Summary + run: | + echo "Pushed to ${CODEARTIFACT_DOMAIN}/${CODEARTIFACT_REPO}:" >> "$GITHUB_STEP_SUMMARY" + ls -1 ./artifacts/*.nupkg | sed 's#.*/# - #' >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml deleted file mode 100644 index e4e2afc..0000000 --- a/.github/workflows/publish-nuget.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Publish Nuget package - -on: - push: - branches: - master - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v1 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.100 - - - name: Build - run: dotnet build --configuration Release - shell: bash - - - name: Publish SqsPoller Nuget release package - shell: bash - env: - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} - run: dotnet nuget push src/SqsPoller/bin/Release/SqsPoller.*.*.*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json - - - name: Publish SqsPoller.Extensions.Publisher Nuget release package - shell: bash - env: - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} - run: dotnet nuget push src/SqsPoller.Extensions.Publisher/bin/Release/SqsPoller.Extensions.Publisher.*.*.*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/.github/workflows/publish-prerelease-codeartifact.yml b/.github/workflows/publish-prerelease-codeartifact.yml new file mode 100644 index 0000000..9a08f19 --- /dev/null +++ b/.github/workflows/publish-prerelease-codeartifact.yml @@ -0,0 +1,83 @@ +name: Publish NuGet prerelease to CodeArtifact + +# Publishes a prerelease build of each pull request so consumers can test a change +# before it is tagged. Replaces the previous workflow that pushed prereleases to +# public nuget.org. +# +# Pull requests opened from a fork do not receive `id-token: write`, so the OIDC +# step cannot assume the AWS role there and this workflow will fail for them. +# Branches in this repository are unaffected. +on: + pull_request: + branches: + - master + +permissions: + id-token: write + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + publish-prerelease: + # GitHub-hosted: the self-hosted `gha-runner-scale-set` label is not available + # to this repository, so jobs targeting it stay queued forever. OIDC works the + # same on hosted runners. + runs-on: ubuntu-latest + env: + CODEARTIFACT_DOMAIN: "idt" + CODEARTIFACT_DOMAIN_OWNER: "416223954868" + CODEARTIFACT_REPO: "team_caf-nuget" + CODEARTIFACT_TOOL: "dotnet" + + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::101838717447:role/github-actions-role + aws-region: ${{ secrets.AWS_REGION || 'us-east-1' }} + + - name: Log in to CodeArtifact + run: | + aws codeartifact login --tool ${{ env.CODEARTIFACT_TOOL }} \ + --domain ${{ env.CODEARTIFACT_DOMAIN }} \ + --domain-owner ${{ env.CODEARTIFACT_DOMAIN_OWNER }} \ + --repository ${{ env.CODEARTIFACT_REPO }} + + # -p:GeneratePackageOnBuild=false: see the release workflow; without it SDK 10 + # fails with NU5026. + # The csproj declares X.Y.Z$(VersionSuffix), so the suffix + # is concatenated directly and must carry its own leading dash. + - name: Pack prerelease + run: | + SUFFIX="-prerelease-$(date +%Y%m%d%H%M%S)" + dotnet pack src/SqsPoller/SqsPoller.csproj \ + -c Release -o ./artifacts -p:GeneratePackageOnBuild=false --version-suffix "$SUFFIX" + dotnet pack src/SqsPoller.Extensions.Publisher/SqsPoller.Extensions.Publisher.csproj \ + -c Release -o ./artifacts -p:GeneratePackageOnBuild=false --version-suffix "$SUFFIX" + + # Both package names are also reachable through the feed's public nuget.org + # external connection, so CodeArtifact defaults them to publish=BLOCK. Each + # needs publish=ALLOW,upstream=BLOCK set once via + # `aws codeartifact put-package-origin-configuration`; otherwise the push + # below returns a bare 400. + - name: Push to CodeArtifact + run: | + dotnet nuget push "./artifacts/*.nupkg" \ + --source ${{ env.CODEARTIFACT_DOMAIN }}/${{ env.CODEARTIFACT_REPO }} \ + --api-key unused \ + --skip-duplicate + + - name: Summary + run: | + echo "Prerelease pushed to ${CODEARTIFACT_DOMAIN}/${CODEARTIFACT_REPO}:" >> "$GITHUB_STEP_SUMMARY" + ls -1 ./artifacts/*.nupkg | sed 's#.*/# - #' >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/publish-prerelease-nuget.yml b/.github/workflows/publish-prerelease-nuget.yml deleted file mode 100644 index 8f71fea..0000000 --- a/.github/workflows/publish-prerelease-nuget.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Publish Nuget prerelease package - -on: - pull_request: - branches: - master - -jobs: - build: - name: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v1 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.100 - - - name: Build - run: dotnet build --configuration Release --version-suffix -prerelease-$(date +%Y%m%d%H%M%S) - shell: bash - - - name: Publish SqsPoller Nuget pre-release package - shell: bash - env: - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} - run: dotnet nuget push src/SqsPoller/bin/Release/SqsPoller.*.*.*-prerelease-*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json - - - name: Publish SqsPoller.Extensions.Publisher Nuget pre-release package - shell: bash - env: - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} - run: dotnet nuget push src/SqsPoller.Extensions.Publisher/bin/Release/SqsPoller.Extensions.Publisher.*.*.*-prerelease-*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/nuget-apikey b/nuget-apikey deleted file mode 100644 index bf46456..0000000 Binary files a/nuget-apikey and /dev/null differ diff --git a/src/SqsPoller.Extensions.Publisher/SqsPoller.Extensions.Publisher.csproj b/src/SqsPoller.Extensions.Publisher/SqsPoller.Extensions.Publisher.csproj index d71ccd0..62f9994 100644 --- a/src/SqsPoller.Extensions.Publisher/SqsPoller.Extensions.Publisher.csproj +++ b/src/SqsPoller.Extensions.Publisher/SqsPoller.Extensions.Publisher.csproj @@ -7,8 +7,8 @@ Alexey Bogdan Alexey Bogdan A small library that helps ASP.NET Core applications easily consume messages from a SQS queue - https://github.com/AlexeyBogdan95/SqsPoller - https://www.nuget.org/packages/SqsPoller/ + https://github.com/coretech/SqsPoller + https://github.com/coretech/SqsPoller true latest enable diff --git a/src/SqsPoller/SqsPoller.csproj b/src/SqsPoller/SqsPoller.csproj index 40f8275..bca3829 100644 --- a/src/SqsPoller/SqsPoller.csproj +++ b/src/SqsPoller/SqsPoller.csproj @@ -7,8 +7,8 @@ Alexey Bogdan Alexey Bogdan A small library that helps ASP.NET Core applications easily consume messages from a SQS queue - https://github.com/AlexeyBogdan95/SqsPoller - https://www.nuget.org/packages/SqsPoller/ + https://github.com/coretech/SqsPoller + https://github.com/coretech/SqsPoller true latest enable