-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (73 loc) · 2.88 KB
/
check-and-release.yaml
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
name: "Check and Release NuGet Packages"
on:
push:
branches:
- main
permissions:
contents: write
actions: write
jobs:
check:
name: Check Packages Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
is_published: ${{ steps.nuget_exists.outputs.exists }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup .NET
uses: ./.github/actions/setup-dotnet
- name: Install xmllint
run: sudo apt install -y libxml2-utils
working-directory: ./
shell: bash
- name: Extract Version from Directory.Build.props
id: version
run: |
# Extract the default version from Directory.Build.props (e.g., 0.0.5)
DEFAULT_VERSION=$(xmllint --xpath "string(//*[local-name()='DefaultVersion'])" Directory.Build.props)
# Extract the template version from Package.props (e.g., "$(DefaultVersion)-beta")
VERSION_TEMPLATE=$(xmllint --xpath "string(//*[local-name()='PackageVersion'])" Package.props)
# Replace the template version with the actual version
VERSION=${VERSION_TEMPLATE/'$(DefaultVersion)'/$DEFAULT_VERSION}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check If Nuget Package Exists
id: nuget_exists
shell: bash
working-directory: ./
run: |
LATEST_VERSION=$(curl -s "https://api.nuget.org/v3-flatcontainer/aptos/index.json" | jq -r '.versions | last')
# Check if the latest version is the same as the current version
if [ "$LATEST_VERSION" == "${{ steps.version.outputs.version }}" ]; then
echo "Nuget package exists (${{ steps.version.outputs.version }})"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Nuget package does not exist (${{ steps.version.outputs.version }})"
echo "exists=false" >> $GITHUB_OUTPUT
fi
release:
name: Pack and Publish Packages
needs: check
runs-on: ubuntu-latest
if: ${{ needs.check.outputs.is_published == 'false' }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup .NET
uses: ./.github/actions/setup-dotnet
- name: Run Tests
run: dotnet test --no-restore --verbosity normal
working-directory: ./Aptos.Tests
shell: bash
- name: Pack Packages
run: dotnet pack --configuration Release --no-build --output ./artifacts
- name: Publish Packages to NuGet
run: |
dotnet nuget push ./artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
- name: Tag Release
run: |
git tag v${{ needs.check.outputs.version }}
git push origin v${{ needs.check.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}