Skip to content

Commit

Permalink
test: fix bug for customers test for upgrading packages (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi Hadeli committed Feb 10, 2023
1 parent 79dfe1d commit 0dc2dfc
Show file tree
Hide file tree
Showing 17 changed files with 559 additions and 364 deletions.
52 changes: 0 additions & 52 deletions .github/actions/app-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,41 +122,6 @@ runs:
echo "app version is: $LATEST_TAG"
fi
- name: csproj version
shell: bash
if: success()
# our environment is available in this subsequent step
run: |
echo update app version to ${{ env.APP_VERSION }}
./update-version.sh "$APP_VERSION"
- run: |
git pull origin ${{ github.ref_name }}
shell: bash
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md
# https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md
# https://github.com/peter-evans/create-pull-request/issues/1608
- name: Create Update Version Pull Request
uses: peter-evans/create-pull-request@v4
if: success() && steps.semantic-version.outputs.semantic_nextRelease_version != ''
with:
author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
commit-message: "chore(release): 猬嗭笍 upgrading application version to: ${{ steps.semantic-version.outputs.semantic_nextRelease_version }} [skip ci]"
title: "chore(release): 猬嗭笍 upgrading application version to: ${{ steps.semantic-version.outputs.semantic_nextRelease_version }} [skip ci]"
token: ${{ inputs.token }}
delete-branch: true
# https://github.com/peter-evans/create-pull-request#alternative-strategy---always-create-a-new-pull-request-branch
# branch-suffix: timestamp
assignees: mehdihadeli
reviewers: mehdihadeli
branch: upgrade-app-version-${{ steps.semantic-version.outputs.semantic_nextRelease_version }}
labels: |
chore
# https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
add-paths: |
*.Packages.props
# Save version in the artifacts to use in CD process
- name: Save Version Name
if: success()
Expand All @@ -169,20 +134,3 @@ runs:
with:
name: ${{ inputs.service-name}}_version_artifacts
path: version_name.txt

# # https://github.com/semantic-release/semantic-release/discussions/2557
# # https://github.com/semantic-release/github/issues/175
# # this needs a PAT with write permission without doing pull request
# - name: Commit Updated Application Version File
# uses: stefanzweifel/git-auto-commit-action@v4
# if: ${{ success() }}
# with:
# commit_message: 'chore(release): 猬嗭笍 upgrading application version to: ${{ steps.semantic-version.outputs.semantic_nextRelease_version }} [skip ci]'
# file_pattern: '**/Directory.Packages.props'
# disable_globbing: true
# # https://github.com/stefanzweifel/git-auto-commit-action#usage
# commit_author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # defaults to author of the commit that triggered the run
# commit_user_name: github-actions[bot] # defaults to "github-actions[bot]"
# commit_user_email: github-actions[bot]@users.noreply.github.com # defaults to "41898282+github-actions[bot]@users.noreply.github.com"


20 changes: 2 additions & 18 deletions .github/actions/test-coverage/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ runs:
# get generated summary from `CodeCoverageSummary` step
path: code-coverage-results.md

# https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
- name: Write to Job Summary
shell: bash
if: success()
Expand All @@ -108,21 +110,3 @@ runs:
with:
github-token: ${{ inputs.token }}
path-to-lcov: "output/test-results/lcov.info"

# GitHub Api call permissions problem here
# https://github.com/dorny/test-reporter
# https://github.com/dorny/test-reporter/pull/174
# https://github.com/dorny/test-reporter/issues/168
- name: Test Results
uses: dorny/test-reporter@v1
id: test-report
if: always()
with:
name: DotNET Tests
reporter: dotnet-trx
token: ${{ inputs.token }}
path: "**/test-results.trx"
## https://github.com/dorny/test-reporter#recommended-setup-for-public-repositories
## https://github.com/dorny/test-reporter/blob/0d9714ddc7ff86918ec725a527a3a069419d301a/src/utils/github-utils.ts#L44
## artifact name to download trx test result if it is in seperated workflow with github rest call, if it is not in another workflow skip this
# artifact: "'
85 changes: 59 additions & 26 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,52 +53,85 @@ runs:
# https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not
# https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md
# https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#filters
- name: Run Unit Tests with No Restore
- name: Run Unit Tests
shell: bash
if: ${{ inputs.no-restore == 'true' }}
id: unit-test-step
working-directory: ${{ inputs.tests-path }}
# https://stackoverflow.com/questions/3779701/msbuild-error-msb1008-only-one-project-can-be-specified
# https://octopus.com/blog/githubactions-running-unit-tests
# we should not do 'no-build' here, because our tests not build in build phase (build composite action) and should build here
run: |
for file in $(find . -name "*.csproj" -type f); do
echo "Testing $file"
dotnet test "$file" -c Release --no-restore -p:Exclude="${{ inputs.coverage-exclude }}" -p:CollectCoverage=true -p:CoverletOutputFormat="cobertura%2clcov" -p:SkipAutoProps=true --filter "${{ inputs.unit-test-filter }}" --logger "trx;LogFileName=test-results.trx"
if [ ${{ inputs.no-restore }} == 'true' ]; then
echo "run tests in no-restore mode"
dotnet test "$file" -c Release --no-restore -p:Exclude="${{ inputs.coverage-exclude }}" -p:CollectCoverage=true -p:CoverletOutputFormat="cobertura%2clcov" -p:SkipAutoProps=true --filter "${{ inputs.unit-test-filter }}" --logger "trx;LogFileName=test-results.trx" || true
else
echo "run tests in restore nuget mode"
dotnet test "$file" -c Release -p:Exclude="${{ inputs.coverage-exclude }}" -p:CollectCoverage=true -p:CoverletOutputFormat="cobertura%2clcov" -p:SkipAutoProps=true --filter "${{ inputs.unit-test-filter }}" --logger "trx;LogFileName=test-results.trx" || true
fi
done
- name: Run Unit Tests
- name: Run Integration And EndToEnd Tests
shell: bash
if: ${{ success() && inputs.no-restore == 'false' }}
id: integration-test-step
working-directory: ${{ inputs.tests-path }}
# https://stackoverflow.com/questions/3779701/msbuild-error-msb1008-only-one-project-can-be-specified
# https://octopus.com/blog/githubactions-running-unit-tests
# we should not do 'no-build' here, because our tests not build in build phase (build composite action) and should build here
run: |
for file in $(find . -name "*.csproj" -type f); do
echo "Testing $file"
dotnet test "$file" -c Release -p:Exclude="${{ inputs.coverage-exclude }}" -p:CollectCoverage=true -p:CoverletOutputFormat="cobertura%2clcov" -p:SkipAutoProps=true --filter "${{ inputs.unit-test-filter }}" --logger "trx;LogFileName=test-results.trx"
if [ ${{ inputs.no-restore }} == 'true' ]; then
echo "run tests in no-restore mode"
dotnet test "$file" -c Release --no-restore -p:Exclude="${{ inputs.coverage-exclude }}" -p:CollectCoverage=true -p:CoverletOutputFormat="cobertura%2clcov" -p:SkipAutoProps=true --filter "${{ inputs.integration-test-filter }}" --logger "trx;LogFileName=test-results.trx" || true
else
echo "run tests in restore nuget mode"
echo "run tests in restore nuget mode" dotnet test "$file" -c Release -p:Exclude="${{ inputs.coverage-exclude }}" -p:CollectCoverage=true -p:CoverletOutputFormat="cobertura%2clcov" -p:SkipAutoProps=true --filter "${{ inputs.integration-test-filter }}" --logger "trx;LogFileName=test-results.trx" || true
fi
done
- name: Run Integration And EndToEnd Tests with No Restore
continue-on-error: false
if: ${{ success() && inputs.no-restore == 'true' }}
shell: bash
working-directory: ${{ inputs.tests-path }}
run: |
for file in $(find . -name "*.csproj" -type f); do
echo "Testing $file"
dotnet test "$file" -c Release --no-restore -p:Exclude="${{ inputs.coverage-exclude }}" -p:CollectCoverage=true -p:CoverletOutputFormat="cobertura%2clcov" -p:SkipAutoProps=true --filter "${{ inputs.integration-test-filter }}" --logger "trx;LogFileName=test-results.trx"
done
# GitHub Api call permissions problem here
# https://github.com/dorny/test-reporter/issues/168
# https://octopus.com/blog/githubactions-running-unit-tests
# https://github.com/dorny/test-reporter/issues/67
# https://github.com/phoenix-actions/test-reporting/pull/21
- name: Test Results
uses: phoenix-actions/test-reporting@v10
id: test-report
if: always()
with:
name: ${{ inputs.service-name }} Test Reports
reporter: dotnet-trx
token: ${{ inputs.token }}
# only-summary: 'true'
output-to: "step-summary"
path: "**/test-results.trx"
# Set action as failed if test report contains any failed test
fail-on-error: true
## https://github.com/dorny/test-reporter#recommended-setup-for-public-repositories
## https://github.com/dorny/test-reporter/blob/0d9714ddc7ff86918ec725a527a3a069419d301a/src/utils/github-utils.ts#L44
## artifact name to download trx test result if it is in seperated workflow with github rest call, if it is not in another workflow skip this
# artifact: "'

- name: Run Integration And EndToEnd Tests
continue-on-error: false
if: ${{ success() && inputs.no-restore == 'false' }}
shell: bash
working-directory: ${{ inputs.tests-path }}
run: |
for file in $(find . -name "*.csproj" -type f); do
echo "Testing $file"
dotnet test "$file" -c Release -p:Exclude="${{ inputs.coverage-exclude }}" -p:CollectCoverage=true -p:CoverletOutputFormat="cobertura%2clcov" -p:SkipAutoProps=true --filter "${{ inputs.integration-test-filter }}" --logger "trx;LogFileName=test-results.trx"
done
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
**/test-results.trx
check_name: ${{ inputs.service-name }} Test Result Report
comment_mode: off
github_token: ${{ inputs.token }}
# https://github.com/EnricoMi/publish-unit-test-result-action#configuration
# Configures the state of the created test result check run. With "test failures" it fails if any test fails or test errors occur
fail_on: "test failures"
action_fail: true

- name: Call Composite Action test-coverage
uses: ./.github/actions/test-coverage
# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context
if: success()
id: test-coverage-step
with:
# wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory
Expand Down
152 changes: 152 additions & 0 deletions .github/workflows/app-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Update App Version

on:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
# https://github.com/peter-evans/create-pull-request/issues/1608
schedule:
- cron: '0 0 * * *' # run at midnight every day

workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'info'
type: choice
options:
- info
- warning
- debug

jobs:
update-main-version:
runs-on: ubuntu-latest

permissions:
pull-requests: write # app-version pull request

steps:
- name: Check out code
uses: actions/checkout@v3
with:
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
# Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags
fetch-depth: 0
ref: 'main'
- run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Set Application Version
id: app-version-step
shell: bash
if: success()
# https://gist.github.com/rponte/fdc0724dd984088606b0
# https://linuxhint.com/bash_if_else_examples/
# https://github.com/semantic-release/semantic-release/issues/2703
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
# environment variable available to any 'subsequent steps' (not in the current step that is set) in a workflow job by defining or updating the environment variable and writing this to the GITHUB_ENV environment file
run: |
LATEST_TAG=$(git describe --abbrev=0 --tags --exclude "*dev*" --exclude "*beta*" --exclude "*preview*" --exclude "*ops*" | sed 's/^v//')
echo "latest tag for main branch is: $LATEST_TAG"
echo "APP_VERSION=$LATEST_TAG" >> "$GITHUB_ENV"
./update-version.sh "$LATEST_TAG"
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md
# https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md
# https://github.com/peter-evans/create-pull-request/issues/1608
- name: Create Update Version Pull Request
uses: peter-evans/create-pull-request@v4
if: success()
with:
author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
commit-message: "chore(release): 猬嗭笍 upgrading application version to: $LATEST_TAG [skip ci]"
title: "chore(release): 猬嗭笍 upgrading application version to: $LATEST_TAG [skip ci]"
token: ${{ secrets.GITHUB_TOKEN }}
delete-branch: true
# https://github.com/peter-evans/create-pull-request#alternative-strategy---always-create-a-new-pull-request-branch
# branch-suffix: timestamp
assignees: mehdihadeli
reviewers: mehdihadeli
branch: upgrade-app-version-${{ env.APP_VERSION }}
labels: |
chore
# https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
add-paths: |
*.Packages.props
update-develop-version:
runs-on: ubuntu-latest

permissions:
pull-requests: write # app-version pull request

steps:
- name: Check out code
uses: actions/checkout@v3
with:
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
# Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags
fetch-depth: 0
ref: 'develop'
- run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Set Application Version
id: app-version-step
shell: bash
if: success()
# https://gist.github.com/rponte/fdc0724dd984088606b0
# https://linuxhint.com/bash_if_else_examples/
# https://github.com/semantic-release/semantic-release/issues/2703
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
# environment variable available to any 'subsequent steps' (not in the current step that is set) in a workflow job by defining or updating the environment variable and writing this to the GITHUB_ENV environment file
run: |
LATEST_TAG=$(git describe --abbrev=0 --tags --match "*dev*" | sed 's/^v//')
echo "latest tag for develop branch is: $LATEST_TAG"
echo "APP_VERSION=$LATEST_TAG" >> "$GITHUB_ENV"
./update-version.sh "$LATEST_TAG"
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md
# https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md
# https://github.com/peter-evans/create-pull-request/issues/1608
- name: Create Update Version Pull Request
uses: peter-evans/create-pull-request@v4
if: success()
with:
author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
commit-message: "chore(release): 猬嗭笍 upgrading application version to: $LATEST_TAG [skip ci]"
title: "chore(release): 猬嗭笍 upgrading application version to: $LATEST_TAG [skip ci]"
token: ${{ secrets.GITHUB_TOKEN }}
delete-branch: true
# https://github.com/peter-evans/create-pull-request#alternative-strategy---always-create-a-new-pull-request-branch
# branch-suffix: timestamp
assignees: mehdihadeli
reviewers: mehdihadeli
branch: upgrade-app-version-${{ env.APP_VERSION }}
labels: |
chore
# https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
add-paths: |
*.Packages.props
# # https://github.com/semantic-release/semantic-release/discussions/2557
# # https://github.com/semantic-release/github/issues/175
# # this needs a PAT with write permission without doing pull request
# - name: Commit Updated Application Version File
# uses: stefanzweifel/git-auto-commit-action@v4
# if: ${{ success() }}
# with:
# commit_message: 'chore(release): 猬嗭笍 upgrading application version to: ${{ steps.semantic-version.outputs.semantic_nextRelease_version }} [skip ci]'
# file_pattern: '**/Directory.Packages.props'
# disable_globbing: true
# # https://github.com/stefanzweifel/git-auto-commit-action#usage
# commit_author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # defaults to author of the commit that triggered the run
# commit_user_name: github-actions[bot] # defaults to "github-actions[bot]"
# commit_user_email: github-actions[bot]@users.noreply.github.com # defaults to "41898282+github-actions[bot]@users.noreply.github.com"


0 comments on commit 0dc2dfc

Please sign in to comment.