Skip to content

Commit 4917d3c

Browse files
authored
Merge pull request #533 from github/update-v1.0.0-ff75ec7f
Merge main into v1
2 parents 6764ac6 + dd66f44 commit 4917d3c

26 files changed

+350
-52
lines changed

.github/update-release-branch.py

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
import requests
55
import subprocess
66
import sys
7+
import json
8+
import datetime
9+
import os
10+
11+
EMPTY_CHANGELOG = """# CodeQL Action and CodeQL Runner Changelog
12+
13+
## [UNRELEASED]
14+
15+
"""
716

817
# The branch being merged from.
918
# This is the one that contains day-to-day development work.
@@ -49,32 +58,40 @@ def open_pr(repo, all_commits, short_main_sha, branch_name):
4958
commits_without_pull_requests = sorted(commits_without_pull_requests, key=lambda c: c.commit.author.date)
5059

5160
# Start constructing the body text
52-
body = 'Merging ' + short_main_sha + ' into ' + LATEST_RELEASE_BRANCH
61+
body = []
62+
body.append('Merging ' + short_main_sha + ' into ' + LATEST_RELEASE_BRANCH)
5363

5464
conductor = get_conductor(repo, pull_requests, commits_without_pull_requests)
55-
body += '\n\nConductor for this PR is @' + conductor
65+
body.append('')
66+
body.append('Conductor for this PR is @' + conductor)
5667

5768
# List all PRs merged
5869
if len(pull_requests) > 0:
59-
body += '\n\nContains the following pull requests:'
70+
body.append('')
71+
body.append('Contains the following pull requests:')
6072
for pr in pull_requests:
6173
merger = get_merger_of_pr(repo, pr)
62-
body += '\n- #' + str(pr.number)
63-
body += ' - ' + pr.title
64-
body += ' (@' + merger + ')'
74+
body.append('- #' + str(pr.number) + ' - ' + pr.title +' (@' + merger + ')')
6575

6676
# List all commits not part of a PR
6777
if len(commits_without_pull_requests) > 0:
68-
body += '\n\nContains the following commits not from a pull request:'
78+
body.append('')
79+
body.append('Contains the following commits not from a pull request:')
6980
for commit in commits_without_pull_requests:
70-
body += '\n- ' + commit.sha
71-
body += ' - ' + get_truncated_commit_message(commit)
72-
body += ' (@' + commit.author.login + ')'
81+
body.append('- ' + commit.sha + ' - ' + get_truncated_commit_message(commit) + ' (@' + commit.author.login + ')')
82+
83+
body.append('')
84+
body.append('Please review the following:')
85+
body.append(' - [ ] The CHANGELOG displays the correct version and date.')
86+
body.append(' - [ ] The CHANGELOG includes all relevant, user-facing changes since the last release.')
87+
body.append(' - [ ] There are no unexpected commits being merged into the ' + LATEST_RELEASE_BRANCH + ' branch.')
88+
body.append(' - [ ] The docs team is aware of any documentation changes that need to be released.')
89+
body.append(' - [ ] The mergeback PR is merged back into ' + MAIN_BRANCH + ' after this PR is merged.')
7390

7491
title = 'Merge ' + MAIN_BRANCH + ' into ' + LATEST_RELEASE_BRANCH
7592

7693
# Create the pull request
77-
pr = repo.create_pull(title=title, body=body, head=branch_name, base=LATEST_RELEASE_BRANCH)
94+
pr = repo.create_pull(title=title, body='\n'.join(body), head=branch_name, base=LATEST_RELEASE_BRANCH)
7895
print('Created PR #' + str(pr.number))
7996

8097
# Assign the conductor
@@ -95,7 +112,7 @@ def get_conductor(repo, pull_requests, other_commits):
95112
# This will not include any commits that exist on the release branch
96113
# that aren't on main.
97114
def get_commit_difference(repo):
98-
commits = run_git('log', '--pretty=format:%H', ORIGIN + '/' + LATEST_RELEASE_BRANCH + '..' + MAIN_BRANCH).strip().split('\n')
115+
commits = run_git('log', '--pretty=format:%H', ORIGIN + '/' + LATEST_RELEASE_BRANCH + '..' + ORIGIN + '/' + MAIN_BRANCH).strip().split('\n')
99116

100117
# Convert to full-fledged commit objects
101118
commits = [repo.get_commit(c) for c in commits]
@@ -135,17 +152,40 @@ def get_pr_for_commit(repo, commit):
135152
def get_merger_of_pr(repo, pr):
136153
return repo.get_commit(pr.merge_commit_sha).author.login
137154

155+
def get_current_version():
156+
with open('package.json', 'r') as f:
157+
return json.load(f)['version']
158+
159+
def get_today_string():
160+
today = datetime.datetime.today()
161+
return '{:%d %b %Y}'.format(today)
162+
163+
def update_changelog(version):
164+
if (os.path.exists('CHANGELOG.md')):
165+
content = ''
166+
with open('CHANGELOG.md', 'r') as f:
167+
content = f.read()
168+
else:
169+
content = EMPTY_CHANGELOG
170+
171+
newContent = content.replace('[UNRELEASED]', version + ' - ' + get_today_string(), 1)
172+
173+
with open('CHANGELOG.md', 'w') as f:
174+
f.write(newContent)
175+
176+
138177
def main():
139178
if len(sys.argv) != 3:
140179
raise Exception('Usage: update-release.branch.py <github token> <repository nwo>')
141180
github_token = sys.argv[1]
142181
repository_nwo = sys.argv[2]
143182

144183
repo = Github(github_token).get_repo(repository_nwo)
184+
version = get_current_version()
145185

146186
# Print what we intend to go
147187
print('Considering difference between ' + MAIN_BRANCH + ' and ' + LATEST_RELEASE_BRANCH)
148-
short_main_sha = run_git('rev-parse', '--short', MAIN_BRANCH).strip()
188+
short_main_sha = run_git('rev-parse', '--short', ORIGIN + '/' + MAIN_BRANCH).strip()
149189
print('Current head of ' + MAIN_BRANCH + ' is ' + short_main_sha)
150190

151191
# See if there are any commits to merge in
@@ -157,7 +197,7 @@ def main():
157197
# The branch name is based off of the name of branch being merged into
158198
# and the SHA of the branch being merged from. Thus if the branch already
159199
# exists we can assume we don't need to recreate it.
160-
new_branch_name = 'update-' + LATEST_RELEASE_BRANCH + '-' + short_main_sha
200+
new_branch_name = 'update-v' + version + '-' + short_main_sha
161201
print('Branch name is ' + new_branch_name)
162202

163203
# Check if the branch already exists. If so we can abort as this script
@@ -168,7 +208,15 @@ def main():
168208

169209
# Create the new branch and push it to the remote
170210
print('Creating branch ' + new_branch_name)
171-
run_git('checkout', '-b', new_branch_name, MAIN_BRANCH)
211+
run_git('checkout', '-b', new_branch_name, ORIGIN + '/' + MAIN_BRANCH)
212+
213+
print('Updating changelog')
214+
update_changelog(version)
215+
216+
# Create a commit that updates the CHANGELOG
217+
run_git('add', 'CHANGELOG.md')
218+
run_git('commit', '-m', version)
219+
172220
run_git('push', ORIGIN, new_branch_name)
173221

174222
# Open a PR to update the branch
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# This workflow runs after a release of the action.
2+
# It merges any changes from the release back into the
3+
# main branch. Typically, this is just a single commit
4+
# that updates the changelog.
5+
name: Tag release and merge back
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
baseBranch:
11+
description: 'The base branch to merge into'
12+
default: main
13+
required: false
14+
15+
push:
16+
branches:
17+
- v1
18+
19+
pull_request:
20+
paths:
21+
- .github/workflows/post-release-mergeback.yml
22+
23+
jobs:
24+
merge-back:
25+
runs-on: ubuntu-latest
26+
if: github.repository == 'github/codeql-action'
27+
env:
28+
BASE_BRANCH: "${{ github.event.inputs.baseBranch || 'main' }}"
29+
HEAD_BRANCH: "${{ github.head_ref || github.ref }}"
30+
31+
steps:
32+
- name: Dump GitHub Event context
33+
env:
34+
GITHUB_EVENT_CONTEXT: "${{ toJson(github.event) }}"
35+
run: echo "$GITHUB_EVENT_CONTEXT"
36+
37+
- uses: actions/checkout@v2
38+
- uses: actions/setup-node@v2
39+
40+
- name: Update git config
41+
run: |
42+
git config --global user.email "[email protected]"
43+
git config --global user.name "github-actions[bot]"
44+
45+
- name: Get version and new branch
46+
id: getVersion
47+
run: |
48+
VERSION="v$(jq '.version' -r 'package.json')"
49+
SHORT_SHA="${GITHUB_SHA:0:8}"
50+
echo "::set-output name=version::$VERSION"
51+
NEW_BRANCH="mergeback/${VERSION}-to-${BASE_BRANCH}-${SHORT_SHA}"
52+
echo "::set-output name=newBranch::$NEW_BRANCH"
53+
54+
55+
- name: Dump branches
56+
env:
57+
NEW_BRANCH: "${{ steps.getVersion.outputs.newBranch }}"
58+
run: |
59+
echo "BASE_BRANCH $BASE_BRANCH"
60+
echo "HEAD_BRANCH $HEAD_BRANCH"
61+
echo "NEW_BRANCH $NEW_BRANCH"
62+
63+
- name: Create mergeback branch
64+
env:
65+
NEW_BRANCH: "${{ steps.getVersion.outputs.newBranch }}"
66+
run: |
67+
git checkout -b "$NEW_BRANCH"
68+
69+
- name: Check for tag
70+
id: check
71+
env:
72+
VERSION: "${{ steps.getVersion.outputs.version }}"
73+
run: |
74+
set +e # don't fail on an errored command
75+
git ls-remote --tags origin | grep "$VERSION"
76+
EXISTS="$?"
77+
if [ "$EXISTS" -ne 0 ]; then
78+
echo "::set-output name=exists::true"
79+
echo "Tag $TAG exists. Not going to re-release."
80+
fi
81+
82+
# we didn't tag the release during the update-release-branch workflow because the
83+
# commit that actually makes it to the release branch is a merge commit,
84+
# and not yet known during the first workflow. We tag now because we know the correct commit.
85+
- name: Tag release
86+
if: steps.check.outputs.exists == 'true'
87+
env:
88+
VERSION: ${{ steps.getVersion.outputs.version }}
89+
run: |
90+
git tag -a "$VERSION" -m "$VERSION"
91+
git push origin --follow-tags "$VERSION"
92+
93+
- name: Create mergeback branch
94+
if: steps.check.outputs.exists == 'true'
95+
env:
96+
VERSION: "${{ steps.getVersion.outputs.version }}"
97+
NEW_BRANCH: "${{ steps.getVersion.outputs.newBranch }}"
98+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
99+
run: |
100+
set -exu
101+
PR_TITLE="Mergeback $VERSION $HEAD_BRANCH into $BASE_BRANCH"
102+
PR_BODY="Updates version and changelog."
103+
104+
# Update the changelog
105+
perl -i -pe 's/^/## \[UNRELEASED\]\n\n/ if($.==3)' CHANGELOG.md
106+
git add .
107+
git commit -m "Update changelog and version after $VERSION"
108+
npm version patch
109+
110+
# when running this workflow on a PR, this is just a test.
111+
# so put into draft mode.
112+
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
113+
DRAFT="--draft"
114+
else
115+
DRAFT=""
116+
fi
117+
118+
git push origin "$NEW_BRANCH"
119+
gh pr create \
120+
--head "$NEW_BRANCH" \
121+
--base "$BASE_BRANCH" \
122+
--title "$PR_TITLE" \
123+
--body "$PR_BODY" \
124+
"$DRAFT"

.github/workflows/update-release-branch.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ jobs:
2222
- name: Set up Python
2323
uses: actions/setup-python@v2
2424
with:
25-
python-version: 3.5
25+
python-version: 3.8
2626

2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
3030
pip install PyGithub==1.51 requests
3131
32+
- name: Update git config
33+
run: |
34+
git config --global user.email "[email protected]"
35+
git config --global user.name "github-actions[bot]"
36+
3237
- name: Update release branch
3338
run: python .github/update-release-branch.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }}

.github/workflows/update-supported-enterprise-server-versions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
jobs:
88
update-supported-enterprise-server-versions:
99
runs-on: ubuntu-latest
10+
if: ${{ github.repository == 'github/codeql-action' }}
1011

1112
steps:
1213
- name: Setup Python

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CodeQL Action and CodeQL Runner Changelog
22

3-
## [UNRELEASED]
3+
## 1.0.0 - 31 May 2021
44

55
- Add this changelog file. [#507](https://github.com/github/codeql-action/pull/507)
6-
- Improve grouping of analysis logs. Add a new log group containing a summary of metrics and diagnostics, if they were produced by CodeQL builtin queries. [#515](https://github.com/github/codeql-action/pull/515)
6+
- Improve grouping of analysis logs. Add a new log group containing a summary of metrics and diagnostics, if they were produced by CodeQL builtin queries. [#515](https://github.com/github/codeql-action/pull/515)
7+
- Add metrics and diagnostics summaries from custom query suites to the analysis summary log group. [#532](https://github.com/github/codeql-action/pull/532)

lib/analyze.js

Lines changed: 22 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)