Skip to content

Commit ec029cd

Browse files
authored
Rework Nuget Package publication (#11)
1 parent d099496 commit ec029cd

10 files changed

+284
-31
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'Pull request check enforcer'
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
check_branch:
8+
name: Check branches
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Check source branch
13+
if: github.base_ref == 'main' && github.head_ref != 'release/**'
14+
run: |
15+
echo "ERROR: You can only merge to main from a release/** branch."
16+
exit 1
17+
18+
- name: Check destination branch
19+
if: github.head_ref == 'release/**' && github.base_ref != 'main'
20+
run: |
21+
echo "ERROR: You can only merge a release/** branch into main."
22+
exit 1
23+

.github/workflows/dotnet-ci.yaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ run-name: Continuous Integration
33

44
on:
55
push:
6-
branches: [ "feature/*" ]
7-
paths-ignore:
8-
- 'samples/**'
9-
pull_request_target:
10-
branches: [ "main" ]
11-
types: [closed]
12-
6+
branches: ["feature/*"]
7+
paths:
8+
- "src/**"
9+
- "tests/**"
10+
1311
concurrency:
1412
group: ci-${{ github.workflow }}-${{ github.actor_id }}
1513
cancel-in-progress: true
1614

1715
jobs:
1816
build_and_test:
1917
name: Build and Test
20-
uses: ./.github/workflows/wf-build-test.yaml
18+
uses: ./.github/workflows/wf-build-test.yaml
19+
with:
20+
buildConfiguration: "Debug"
21+
22+
update_version:
23+
name: Update Version
24+
needs: build_and_test
25+
permissions:
26+
contents: write
27+
uses: ./.github/workflows/wf-update-version.yaml
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: .NET CI
2+
run-name: Continuous Integration
3+
4+
on:
5+
pull_request_target:
6+
branches: ["develop"]
7+
types: [closed]
8+
9+
concurrency:
10+
group: ci-${{ github.workflow }}-${{ github.actor_id }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build_and_test:
15+
name: Build and Test
16+
uses: ./.github/workflows/wf-build-test.yaml
17+
18+
update_version:
19+
name: Update Version
20+
needs: build_and_test
21+
permissions:
22+
contents: write
23+
uses: ./.github/workflows/wf-update-version.yaml
24+
with:
25+
bumpVersion: 0.^.0

.github/workflows/dotnet-release.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ name: .NET Release
22
run-name: Release ${{ github.ref_name }}
33

44
on:
5-
push:
6-
branches: [ "release/*" ]
5+
release:
6+
types: [published]
77

88
concurrency:
99
group: ${{ github.workflow }}-${{ github.ref }}
1010
cancel-in-progress: true
11-
12-
jobs:
11+
12+
jobs:
1313
publish_nuget:
14+
if: github.event.release.draft == false
1415
uses: ./.github/workflows/wf-publish-nuget.yaml
1516
with:
16-
push_package: true
17+
push_package: ${{ github.event.release.prerelease == false }}
1718
secrets:
18-
nuget_api_key: ${{ secrets.NUGET_API_KEY_TEST }}
19+
nuget_api_key: ${{ secrets.NUGET_API_KEY_TEST }}
20+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
4+
name: Build and deploy ASP.Net Core app to Azure Web App - sample-trigger
5+
6+
on:
7+
push:
8+
branches:
9+
- feature/update-samples-and-documentation
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up .NET Core
20+
uses: actions/setup-dotnet@v1
21+
with:
22+
dotnet-version: '8.x'
23+
include-prerelease: true
24+
25+
- name: Build with dotnet
26+
run: dotnet build --configuration Release
27+
28+
- name: dotnet publish
29+
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
30+
31+
- name: Upload artifact for deployment job
32+
uses: actions/upload-artifact@v3
33+
with:
34+
name: .net-app
35+
path: ${{env.DOTNET_ROOT}}/myapp
36+
37+
deploy:
38+
runs-on: ubuntu-latest
39+
needs: build
40+
environment:
41+
name: 'Production'
42+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
43+
permissions:
44+
id-token: write #This is required for requesting the JWT
45+
46+
steps:
47+
- name: Download artifact from build job
48+
uses: actions/download-artifact@v3
49+
with:
50+
name: .net-app
51+
52+
- name: Login to Azure
53+
uses: azure/login@v1
54+
with:
55+
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_410FEBA142964ADC8BDDD567E0E6CF22 }}
56+
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_F98AA0B0793242C187FA3A99A82D66A1 }}
57+
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_9495FAD158814482BE8A7C1AF843FF35 }}
58+
59+
- name: Deploy to Azure Web App
60+
id: deploy-to-webapp
61+
uses: azure/webapps-deploy@v2
62+
with:
63+
app-name: 'sample-trigger'
64+
slot-name: 'Production'
65+
package: .
66+

.github/workflows/wf-build-test.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ on:
55
workflow_call:
66
inputs:
77
buildConfiguration:
8-
description: 'Build Configuration'
8+
description: "Build Configuration"
99
type: string
10-
default: 'Release'
10+
default: "Release"
1111

1212
jobs:
1313
build-project:
1414
name: Build Project & Test
1515
runs-on: ubuntu-latest
1616
env:
1717
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
18-
18+
1919
steps:
2020
- name: Checkout Repository
2121
uses: actions/checkout@v4
22-
22+
2323
- name: Setup .NET Core SDK
2424
uses: actions/setup-dotnet@v4.0.0
2525
with:
@@ -33,12 +33,12 @@ jobs:
3333

3434
- name: Create packages directory
3535
run: mkdir -p packages
36-
36+
3737
- name: Restore dependencies
3838
run: dotnet restore
3939

4040
- name: Build
4141
run: dotnet build --no-restore --configuration ${{ inputs.buildConfiguration }} -p:GeneratePackageOnBuild=false
4242

4343
- name: Test
44-
run: dotnet test --no-build --verbosity normal --configuration ${{ inputs.buildConfiguration }}
44+
run: dotnet test --no-build --verbosity normal --configuration ${{ inputs.buildConfiguration }}

.github/workflows/wf-publish-nuget.yaml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,49 @@ on:
2020
description: 'NuGet API Key'
2121
required: true
2222

23+
env:
24+
PACKAGE_PATH: nupkgs
25+
2326
jobs:
24-
publish-nuget:
25-
name: Publish NuGet Package
27+
prepare-package:
28+
name: Prepare Package
2629
runs-on: ubuntu-latest
27-
env:
28-
package_path: nupkgs
2930

3031
steps:
3132
- name: Checkout Repository
3233
uses: actions/checkout@v4
33-
34+
with:
35+
sparse-checkout: src
36+
3437
- name: Create packages directory
3538
run: mkdir -p packages
36-
39+
3740
- name: Pack
38-
run: dotnet pack $GITHUB_WORKSPACE/InvvardDev.Ifttt.sln --output ${{ env.package_path }} --configuration ${{ inputs.build_configuration }} -p:GeneratePackageOnBuild=false
41+
run: dotnet pack $GITHUB_WORKSPACE/src/InvvardDev.Ifttt.csproj --output $PACKAGE_PATH --configuration ${{ inputs.build_configuration }} -p:GeneratePackageOnBuild=false
3942

4043
- name: Upload Artifact
4144
uses: actions/upload-artifact@v4
4245
with:
4346
name: nuget-packages
44-
path: ${{ env.package_path }}
47+
path: $PACKAGE_PATH
48+
49+
publish-to-nuget:
50+
name: Publish Package to NuGet
51+
runs-on: ubuntu-latest
4552

53+
steps:
4654
- name: Publish to NuGet
4755
if: inputs.push_package
48-
run: dotnet nuget push ${{ env.package_path }}/*.* --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key $nuget_api_key
56+
run: dotnet nuget push $PACKAGE_PATH/*.* --api-key $api_key --source https://api.nuget.org/v3/index.json --skip-duplicate
57+
env:
58+
api_key: ${{ secrets.nuget_api_key }}
59+
60+
publish-to-github:
61+
name: Publish Package to GitHub Packages
62+
runs-on: ubuntu-latest
63+
64+
steps:
65+
- name: Publish to GitHub Packages
66+
run: dotnet nuget push ${{ env.package_path }}/*.* --api-key $api_key --source https://nuget.pkg.github.com/InvvardDev/index.json --skip-duplicate --no-symbols
4967
env:
50-
nuget_api_key: ${{ secrets.nuget_api_key }}
68+
api_key: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/wf-temp.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: On Tag Push
2+
run-name: Tag Push
3+
4+
on:
5+
push:
6+
tags:
7+
- v*
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
github-example-tags:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
sparse-checkout: |
21+
.github
22+
src
23+
tests
24+
25+
# - name: Setup .NET Core
26+
# uses: actions/setup-dotnet@v4
27+
# with:
28+
# dotnet-version: 8.0.x
29+
30+
# - name: Create packages directory
31+
# run: mkdir -p packages
32+
33+
# - name: Install dependencies
34+
# run: dotnet restore
35+
36+
# - name: Build
37+
# run: dotnet build --configuration Release --no-restore -p:GeneratePackageOnBuild=false
38+
39+
- name: Get tagged branch
40+
run: |
41+
tag=${{ github.ref_name }}
42+
sha=$(git rev-list -n 1 $tag)
43+
branch=$(git branch -r --contains $sha | cut -c3- | sed 's/origin\///')
44+
echo Current branch: * $branch *
45+
echo "BRANCH=$branch" >> $GITHUB_ENV
46+
git checkout $branch
47+
48+
- name: Bump VersionPrefix
49+
id: bump_version_prefix
50+
uses: vers-one/dotnet-project-version-updater@v1.5
51+
with:
52+
file: "**/src/*.csproj"
53+
version: bump-build
54+
55+
- name: Push new VersionPrefix
56+
run: |
57+
git config user.name "${{github.event.pusher.name}}"
58+
git config user.email "${{github.event.pusher.email}}"
59+
git add .
60+
git commit -m "Update Version Prefix from ${{ steps.bump_version_prefix.outputs.oldVersion }} to ${{ steps.bump_version_prefix.outputs.newVersion }}"
61+
git push
62+
63+
- name: GitHub Tag Name example
64+
run: |
65+
echo "Tag name from GITHUB_REF_NAME: $GITHUB_REF_NAME"
66+
echo "Tag name from github.ref_name: ${{ github.ref_name }}"
67+

0 commit comments

Comments
 (0)