-
Notifications
You must be signed in to change notification settings - Fork 1
138 lines (124 loc) · 4.51 KB
/
tests.yaml
File metadata and controls
138 lines (124 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: 'Unit Tests'
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
env:
retention_days: 3
permissions:
checks: write
contents: read
pull-requests: write
security-events: write # required for SARIF upload
actions: read
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full git history for version calculation
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v4.2.0
with:
versionSpec: "6.3.x"
- name: Determine Version
id: version_step # step id used as a reference for output values
uses: gittools/actions/gitversion/execute@v4.2.0
env:
DOTNET_GITVERSION_TELEMETRY_OPTOUT: 1
with:
configFilePath: ./GitVersion.yml
- name: Extract version information
id: extract-version
run: |
# Read GitVersion output and replace PullRequest with Patch
VERSION="${{ steps.version_step.outputs.SemVer }}"
# make 0.1.0-PullRequest99.190 to 0.1.0-Patch99.190
VERSION=$(echo "$VERSION" | sed 's/PullRequest/Patch/g')
FULL_SEMVER="${{ steps.version_step.outputs.FullSemVer }}"
MAJOR_MINOR_PATCH="${{ steps.version_step.outputs.MajorMinorPatch }}"
GIT_HASH="${{ steps.version_step.outputs.Sha }}"
GIT_TAG="${{ steps.version_step.outputs.PreReleaseTag }}"
GIT_BRANCH="${{ steps.version_step.outputs.BranchName }}"
COMMIT_COUNT="${{ steps.version_step.outputs.CommitsSinceVersionSource }}"
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Create version.txt content
cat > version-$VERSION.txt << EOF
version=$VERSION
major_minor_patch=$MAJOR_MINOR_PATCH
full_semver=$FULL_SEMVER
git_hash=$GIT_HASH
git_tag=$GIT_TAG
git_branch=$GIT_BRANCH
commit_count=$COMMIT_COUNT
build_date=$BUILD_DATE
EOF
# Output version for other steps
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "MAJOR_MINOR_PATCH=$MAJOR_MINOR_PATCH" >> $GITHUB_OUTPUT
echo "FULL_SEMVER=$FULL_SEMVER" >> $GITHUB_OUTPUT
echo "GIT_HASH=$GIT_HASH" >> $GITHUB_OUTPUT
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_OUTPUT
echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_OUTPUT
echo "COMMIT_COUNT=$COMMIT_COUNT" >> $GITHUB_OUTPUT
# Display version info
echo "Generated version: $VERSION"
echo "Major minor patch: $MAJOR_MINOR_PATCH"
echo "Full semver: $FULL_SEMVER"
echo "Git hash: $GIT_HASH"
echo "Git branch: $GIT_BRANCH"
echo "Commit count: $COMMIT_COUNT"
echo "Build date: $BUILD_DATE"
echo "version.txt content:"
cat version-$VERSION.txt
- name: Update project files with version
run: |
chmod +x scripts/updateVersion.sh
bash scripts/updateVersion.sh
- name: Upload version.txt as artifact
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: version-info
path: version-${{ steps.extract-version.outputs.VERSION }}.txt
retention-days: ${{ env.retention_days }}
- uses: actions/setup-node@v6
with:
node-version: 16
- run: npm ci
- run: npm test
- name: upload junit
uses: actions/upload-artifact@v4
with:
name: junit
path: junit.xml
retention-days: ${{ env.retention_days }}
# displays in summary page
- name: Publish Test Report
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: junit.xml
check_name: Test Results
- run: npm run test:coverage
- name: upload code coverage
uses: actions/upload-artifact@v4
with:
name: Report-CodeCoverage
path: coverage
retention-days: ${{ env.retention_days }}
automerge:
needs: tests
name: Auto-merge PR if tests pass
if: (github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]' || github.actor == 'imgbot[bot]') && needs.tests.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Merge PR
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
merge-method: squash
pull-request-number: ${{ github.event.pull_request.number }}