-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (140 loc) · 6.08 KB
/
sync-dev-and-main.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
# This GitHub Workflow is designed to run automatically after the Release PR, which was created by the `Create Release PR` workflow, is closed.
# This workflow has 2 jobs. One will run if the `Release PR` is successfully merged, indicating that a release should go out.
# The other will run if the `Release PR` was closed and a release is not intended to go out.
name: Sync 'dev' and 'main'
# The workflow will automatically be triggered when any PR is closed.
on:
pull_request:
types: [closed]
permissions:
contents: write
packages: write
jobs:
# This job will check if the PR was successfully merged, it's source branch is `releases/next-release` and target branch is `dev`.
# This indicates that the merged PR was the `Release PR`.
# This job will synchronize `dev` and `main`, create a GitHub Release and delete the `releases/next-release` branch.
sync-dev-and-main:
name: Sync dev and main
if: |
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref == 'releases/next-release' &&
github.event.pull_request.base.ref == 'dev'
runs-on: ubuntu-latest
steps:
# Checkout a full clone of the repo
- name: Checkout code
uses: actions/checkout@v4
with:
ref: dev
fetch-depth: 0
# Install .NET8 which is needed for AutoVer
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
# Build solution to install not-yet published AutoVer package
- name: Build Solution
run: dotnet build
# Create NuGet package to install not-yet published AutoVer package
- name: Create NuGet Package
run: dotnet pack
# Install AutoVer to automate versioning and changelog creation
- name: Install AutoVer
run: dotnet tool install -g --add-source src/AutoVer/bin/Release autover
# Set up a git user to be able to run git commands later on
- name: Setup Git User
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub User"
# Retrieve the release name which is needed for the GitHub Release
- name: Read Release Name
id: read-release-name
run: |
version=$(autover changelog --release-name)
echo "VERSION=$version" >> $GITHUB_OUTPUT
# Retrieve the tag name which is needed for the GitHub Release
- name: Read Tag Name
id: read-tag-name
run: |
tag=$(autover changelog --tag-name)
echo "TAG=$tag" >> $GITHUB_OUTPUT
# Retrieve the changelog which is needed for the GitHub Release
- name: Read Changelog
id: read-changelog
run: |
changelog=$(autover changelog --output-to-console)
echo "CHANGELOG<<EOF"$'\n'"$changelog"$'\n'EOF >> "$GITHUB_OUTPUT"
# Merge dev into main in order to synchronize the 2 branches
- name: Merge dev to main
run: |
git fetch origin
git checkout main
git merge dev
git push origin main
# Create the GitHub Release
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ steps.read-tag-name.outputs.TAG }}" --title "${{ steps.read-release-name.outputs.VERSION }}" --notes "${{ steps.read-changelog.outputs.CHANGELOG }}"
# Push to GitHub Registry
- name: Push to GitHub Registry
run: |
dotnet nuget add source --username philasmar --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/philasmar/index.json"
dotnet nuget push src/AutoVer/bin/Release/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "github"
# Push to NuGet
- name: Push to NuGet
run: dotnet nuget push src/AutoVer/bin/Release/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json"
# Delete the `releases/next-release` branch
- name: Clean up
run: |
git fetch origin
git push origin --delete releases/next-release
# This job will check if the PR was closed, it's source branch is `releases/next-release` and target branch is `dev`.
# This indicates that the closed PR was the `Release PR`.
# This job will delete the tag created by AutoVer and the release branch.
clean-up-closed-release:
name: Clean up closed release
if: |
github.event.pull_request.merged == false &&
github.event.pull_request.head.ref == 'releases/next-release' &&
github.event.pull_request.base.ref == 'dev'
runs-on: ubuntu-latest
steps:
# Checkout a full clone of the repo
- name: Checkout code
uses: actions/checkout@v4
with:
ref: releases/next-release
fetch-depth: 0
# Install .NET8 which is needed for AutoVer
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
# Build solution to install not-yet published AutoVer package
- name: Build Solution
run: dotnet build
# Create NuGet package to install not-yet published AutoVer package
- name: Create NuGet Package
run: dotnet pack
# Install AutoVer to automate versioning and changelog creation
- name: Install AutoVer
run: dotnet tool install -g --add-source src/AutoVer/bin/Release autover
# Set up a git user to be able to run git commands later on
- name: Setup Git User
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub User"
# Retrieve the tag name to be deleted
- name: Read Tag Name
id: read-tag-name
run: |
tag=$(autover changelog --tag-name)
echo "TAG=$tag" >> $GITHUB_OUTPUT
# Delete the tag created by AutoVer and the release branch
- name: Clean up
run: |
git fetch origin
git push --delete origin ${{ steps.read-tag-name.outputs.TAG }}
git push origin --delete releases/next-release