Skip to content

Commit f7481ca

Browse files
Automate supported releases bookkeeping (#4158)
1 parent e304d4c commit f7481ca

17 files changed

+827
-94
lines changed

.github/actions/action-utils.js

+32
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,37 @@ module.exports.installAndRequirePackages = async function(...newPackages)
1818
return requiredPackages;
1919
}
2020

21+
function splitVersionTag(tag) {
22+
const regex = /v(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(-(?<versionLabel>[a-zA-Z]+)\.(?<iteration>\d+))?/;
23+
const releaseVersion = regex.exec(tag);
24+
if (releaseVersion == null) throw "Error: Unexpected tag format";
25+
26+
return [
27+
Number(releaseVersion.groups.major),
28+
Number(releaseVersion.groups.minor),
29+
Number(releaseVersion.groups.patch),
30+
(releaseVersion.groups.iteration === undefined) ? undefined : Number(releaseVersion.groups.iteration),
31+
releaseVersion.groups.versionLabel
32+
];
33+
}
34+
35+
module.exports.isVersionTagRTM = function(tag) {
36+
const [_, __, ___, iteration] = splitVersionTag(tag);
37+
38+
return iteration === undefined;
39+
}
40+
41+
module.exports.friendlyDateFromISODate = function(isoDate) {
42+
if (isoDate === undefined) {
43+
return undefined;
44+
}
45+
46+
return new Date(isoDate).toLocaleString(
47+
"en-us", {
48+
dateStyle: "long"
49+
});
50+
}
51+
52+
module.exports.splitVersionTag = splitVersionTag;
2153
module.exports.readFile = (fileName) => util.promisify(fs.readFile)(fileName, 'utf8');
2254
module.exports.writeFile = (fileName, contents) => util.promisify(fs.writeFile)(fileName, contents);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = async (github, context, baseSha, branchName) => {
2+
const refName = `heads/${branchName}`;
3+
4+
// Check if the ref already exists, if so we will need to fast forward it.
5+
let needToCreateRef = true;
6+
try {
7+
await github.rest.git.getRef({
8+
owner: context.repo.owner,
9+
repo: context.repo.repo,
10+
ref: refName
11+
});
12+
needToCreateRef = false;
13+
} catch {
14+
}
15+
16+
if (needToCreateRef) {
17+
await github.rest.git.createRef({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
sha: baseSha,
21+
ref: `refs/${refName}`
22+
});
23+
} else {
24+
await github.rest.git.updateRef({
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
sha: baseSha,
28+
ref: refName,
29+
force: true
30+
});
31+
}
32+
}

.github/actions/open-pr/action.yml

+17-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ inputs:
44
branch_name:
55
description: 'The branch name to create. Will be prefixed with "bot/".'
66
required: true
7+
base_branch:
8+
description: 'The base branch name to open a PR against. Will default to the current branch if not specified.'
9+
required: false
710
title:
811
description: 'The PR title.'
912
required: true
@@ -22,6 +25,9 @@ inputs:
2225
fail_if_files_unchanged:
2326
description: 'Fails the action if all of the specified files_to_commit are unchanged.'
2427
required: false
28+
update_if_already_exists:
29+
description: 'Allows updating an existing PR, or re-opening it if closed.'
30+
required: false
2531
auth_token:
2632
description: 'The token used to authenticate to GitHub.'
2733
required: true
@@ -37,16 +43,21 @@ runs:
3743
current_branch_name=$(git symbolic-ref --short HEAD)
3844
pr_branch_name="bot/$BRANCH_NAME"
3945
46+
if [[ "$UPDATE_IF_ALREADY_EXISTS" != "true" ]] || [[ "$current_branch_name" != "$pr_branch_name" ]]; then
47+
git checkout -b "$pr_branch_name"
48+
fi
49+
50+
base_branch_name=${BASE_BRANCH_NAME:-${current_branch_name}}
51+
4052
git config user.name "github-actions"
4153
git config user.email "[email protected]"
42-
git checkout -b "$pr_branch_name"
4354
git add ${{ inputs.files_to_commit }}
4455
4556
are_files_changed=""
4657
git diff --name-only --cached --exit-code || are_files_changed="1"
4758
if [ "$are_files_changed" != "1" ]; then
4859
echo "No files changed, nothing to do."
49-
if [ "${{ inputs.fail_if_files_unchanged }}" == "true" ]; then
60+
if [ "$FAIL_IF_FILES_UNCHANGED" == "true" ]; then
5061
exit 1
5162
fi
5263
@@ -61,13 +72,16 @@ runs:
6172
extraArgs="${extraArgs} --draft"
6273
fi
6374
64-
gh pr create --repo "${{ github.repository }}" --base "$current_branch_name" -t "$TITLE" -b "$BODY_MESSAGE" $extraArgs --label "$LABELS"
75+
gh pr create --repo "${{ github.repository }}" --base "$base_branch_name" -t "$TITLE" -b "$BODY_MESSAGE" $extraArgs --label "$LABELS" || [[ "$UPDATE_IF_ALREADY_EXISTS" == "true" ]]
6576
shell: bash
6677
env:
6778
BODY_MESSAGE: ${{ inputs.body }}
6879
BRANCH_NAME: ${{ inputs.branch_name }}
80+
BASE_BRANCH_NAME: ${{ inputs.base_branch }}
6981
COMMIT_MESSAGE: ${{ inputs.commit_message }}
7082
DRAFT: ${{ inputs.draft }}
7183
LABELS: ${{ inputs.labels }}
84+
FAIL_IF_FILES_UNCHANGED: ${{ inputs.fail_if_files_unchanged }}
85+
UPDATE_IF_ALREADY_EXISTS: ${{ inputs.update_if_already_exists }}
7286
TITLE: ${{ inputs.title }}
7387
GITHUB_TOKEN: ${{ inputs.auth_token }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'Update releases json file'
2+
description: 'Update releases json file'
3+
inputs:
4+
auth_token:
5+
description: 'The token used to authenticate to GitHub.'
6+
required: false
7+
releases_json_file:
8+
description: 'The input releases json file path.'
9+
required: true
10+
supported_frameworks:
11+
description: 'The frameworks supported by the new release.'
12+
required: false
13+
end_of_support_discussion_category:
14+
description: 'The discussion category to post about a version going out of support soon.'
15+
required: false
16+
17+
runs:
18+
using: 'node16'
19+
main: 'index.js'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
On ${endOfSupportDate}, the ${majorMinorVersion}.X versions of `dotnet monitor` will be out of support. After this date, we will no longer provide any bug or security fixes for these versions.
2+
3+
Please refer to [Releases](https://github.com/dotnet/dotnet-monitor/blob/main/documentation/releases.md) to see the currently supported versions.
4+
5+
Please update to a newer version in order to remain in support using one of the following:
6+
7+
## .NET Tool
8+
9+
This will update the installation to the most recent release of `dotnet monitor`:
10+
11+
```
12+
dotnet tool update -g dotnet-monitor
13+
```
14+
15+
## Docker Image
16+
17+
Use the Docker image name without specifying a tag to get the most recent release of `dotnet monitor`:
18+
19+
```
20+
docker pull mcr.microsoft.com/dotnet/monitor
21+
```

0 commit comments

Comments
 (0)