Repository navigation
72 lines (55 loc) · 2.34 KB
/
Copy pathrelease.yml
File metadata and controls
72 lines (55 loc) · 2.34 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
name: Release
run-name: Release - ${{ github.ref_name }}
on:
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Extract version from branch name
id: extract_version
run: |
BRANCH_NAME="${{ github.ref_name }}"
VERSION=$(echo "$BRANCH_NAME" | sed -E 's|^release/([0-9]+\.[0-9]+\.[0-9]+)(-.*)?|\1|')
echo "Branch Name: $BRANCH_NAME"
echo "Extracted Version: $VERSION"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Version should be in the format 'x.x.x'."
exit 1
fi
# Export version to the environment
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Restore Dependencies
run: dotnet restore
- name: Build Project
run: dotnet build --no-restore --configuration Release /p:Version=${{ env.VERSION }}
- name: Test Project
run: dotnet test --configuration Release --no-build
- name: Create NuGet Packages
run: dotnet pack --configuration Release --output nupkgs /p:PackageVersion=${{ env.VERSION }} /p:Version=${{ env.VERSION }} --no-build
- name: Push NuGet packages
run: |
for package in OpenSettings.AspNetCore OpenSettings.AspNetCore.Spa OpenSettings; do
dotnet nuget push nupkgs/${package}.${{ env.VERSION }}.nupkg --skip-duplicate --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
done
- name: Set up GitHub Actions bot user details
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Create and push tag
run: |
TAG_NAME="v${{ env.VERSION }}"
git tag $TAG_NAME
git push origin $TAG_NAME
- name: Create GitHub Release
run: gh release create v${{ env.VERSION }} --title "Release v${{ env.VERSION }}" --notes "This is a release of version v${{ env.VERSION }}." --draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}