-
Notifications
You must be signed in to change notification settings - Fork 15
167 lines (156 loc) · 6.65 KB
/
build.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Build
on:
push:
env:
SDK_ERROR_MESSAGES_VERSION: "master"
PACKAGE_SOURCE: https://nuget.pkg.github.com/tatumio/index.json
PUB_PACKAGE_SOURCE: https://api.nuget.org/v3/index.json
PROJECT_PATH: ./Tatum/Tatum.csproj
DEMO_APP_PATH: ./Tatum.Demo/Tatum.Demo.csproj
jobs:
metadata:
runs-on: ubuntu-latest
outputs:
current_branch: ${{ steps.branch-name.outputs.current_branch }}
package_version: ${{ steps.package-version.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v6
- name: Get package version
id: package-version
run: |
stat .version > /dev/null && version=$(<.version)
if [[ ${{ steps.branch-name.outputs.current_branch }} == "develop" || ${{ steps.branch-name.outputs.current_branch }} == "v3" ]]; then
version=$version-alpha${{ github.run_id }}
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
test:
timeout-minutes: 20
runs-on: ubuntu-latest
needs: [metadata]
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Run Tests
run: dotnet test
env:
INTEGRATION_TEST_APIKEY: ${{ secrets.INTEGRATION_TEST_APIKEY }}
NOTIFICATION_TEST_APIKEY: ${{ secrets.NOTIFICATION_TEST_APIKEY }}
build:
runs-on: ubuntu-latest
needs: [metadata, test]
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: nuget/setup-nuget@v1
- name: Download SDK error messages
uses: wei/[email protected]
with:
args: https://raw.githubusercontent.com/tatumio/tatum-sdk-error-mesages/$SDK_ERROR_MESSAGES_VERSION/error-messages.json --output Tatum.Core/Resources/errorMessages.json
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Create package - ${{ needs.metadata.outputs.package_version }}
run: dotnet pack ${{ env.PROJECT_PATH }} --configuration Release -p:NuspecProperties="version=${{ needs.metadata.outputs.package_version }}" --output . -p:TargetFrameworks=netstandard2.0
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: Tatum.${{ needs.metadata.outputs.package_version }}.nupkg
path: ./Tatum.${{ needs.metadata.outputs.package_version }}.nupkg
retention-days: 7
if: |
contains(fromJSON('["main", "develop", "v3"]'), needs.metadata.outputs.current_branch)
nuget_github:
needs: [metadata, build]
if: contains(fromJSON('["main", "develop", "v3"]'), needs.metadata.outputs.current_branch)
runs-on: ubuntu-latest
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- uses: actions/download-artifact@v3
with:
name: Tatum.${{ needs.metadata.outputs.package_version }}.nupkg
- name: Add source
run: dotnet nuget add source --username tatumio --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "${{ env.PACKAGE_SOURCE }}"
- name: Push
run: dotnet nuget push "Tatum.${{ needs.metadata.outputs.package_version }}.nupkg" --skip-duplicate --api-key ${{ secrets.ACTIONS_PACKAGE_SOURCE_PAT }} --source github
test_healthcheck:
runs-on: ubuntu-latest
if: contains(fromJSON('["main", "v3"]'), needs.metadata.outputs.current_branch)
needs: [metadata, nuget_github]
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Add source
run: dotnet nuget add source --username tatumio --password ${{ secrets.ACTIONS_PACKAGE_SOURCE_PAT }} --store-password-in-clear-text --name github "${{ env.PACKAGE_SOURCE }}"
- name: Switch dependency to nuget package
run: |
dotnet remove ${{ env.DEMO_APP_PATH }} reference ${{ env.PROJECT_PATH }}
dotnet add ${{ env.DEMO_APP_PATH }} package Tatum --no-restore --version ${{ needs.metadata.outputs.package_version }}
- name: Build
run: dotnet build ${{ env.DEMO_APP_PATH }}
- name: Run healtcheck on Demo app
run: ./app_hck.sh
env:
NOTIFICATION_TEST_APIKEY: ${{ secrets.NOTIFICATION_TEST_APIKEY }}
release:
if: needs.metadata.outputs.current_branch == 'main'
runs-on: ubuntu-latest
needs: [metadata, build, test_healthcheck]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Git config
run: |
git config --local user.name github-actions
git config --local user.email [email protected]
- name: Get latest release
id: get_latest_release
run: |
latest_tag=$(curl -s --max-time 5 https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest | jq -r '.tag_name')
echo "LATEST_RELEASE_TAG=$latest_tag" >> $GITHUB_ENV
- name: Ensure package version is updated
run: |
[ "${{needs.metadata.outputs.package_version}}" = "${{env.LATEST_RELEASE_TAG}}" ] && echo "Error: Package version is the same as the latest release" && exit 1 || exit 0
- name: Get release notes
id: get_release_notes
uses: ffurrer2/extract-release-notes@v1
# TAG the repo
- name: Create tag ${{ needs.metadata.outputs.package_version }}
uses: rickstaa/action-create-tag@v1
with:
tag: "${{ needs.metadata.outputs.package_version }}"
- name: "Create a GitHub release ${{ needs.metadata.outputs.package_version }}"
# Create release using the tag above
uses: ncipollo/release-action@v1
with:
tag: "${{needs.metadata.outputs.package_version}}"
name: "${{needs.metadata.outputs.package_version}}"
body: |
${{ steps.get_release_notes.outputs.release_notes }}
nuget:
if: needs.metadata.outputs.current_branch == 'main'
runs-on: ubuntu-latest
needs: [metadata, build, test_healthcheck]
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- uses: actions/download-artifact@v3
with:
name: Tatum.${{ needs.metadata.outputs.package_version }}.nupkg
- name: Push to ${{ steps.set_source.outputs.pkg_src_short_name }}
run: dotnet nuget push "./Tatum.${{ needs.metadata.outputs.package_version }}.nupkg" --skip-duplicate --api-key ${{ secrets.NUGET_PUBLISH_KEY }} --source ${{ env.PUB_PACKAGE_SOURCE }}