Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into v2 #1004

Merged
merged 79 commits into from Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
a92e877
Use the `checkout_path` for getting the commit oid
aeisenberg Feb 28, 2022
5c2600e
Merge branch 'main' into aeisenberg/checkout-path-commitoid
aeisenberg Mar 1, 2022
76c3e91
Bump timeout to 45 minutes
aeisenberg Mar 11, 2022
1457c16
Update changelog and version after v1.1.5
invalid-email-address Mar 15, 2022
ac7bd44
1.1.6
invalid-email-address Mar 15, 2022
34905f6
Update checked-in dependencies
invalid-email-address Mar 15, 2022
d0ee2b4
Merge pull request #983 from github/mergeback/v1.1.5-to-main-88347664
cklin Mar 15, 2022
f60bb5c
Include CodeQL CLI and action versions in status reports
cklin Mar 17, 2022
3886398
Merge pull request #987 from cklin/report-versions
cklin Mar 17, 2022
243ebf6
Update supported GitHub Enterprise Server versions.
web-flow Mar 18, 2022
0a71301
refactor: replace deprecated String.prototype.substr()
CommanderRoot Mar 20, 2022
f71aeef
Merge pull request #988 from CommanderRoot/refactor/rm-deprecated-substr
henrymercer Mar 21, 2022
c592f89
Merge branch 'main' into update-supported-enterprise-server-versions
henrymercer Mar 21, 2022
1d81ec4
Merge pull request #984 from github/update-supported-enterprise-serve…
henrymercer Mar 21, 2022
6de8537
Update README now build tracing is compatible with Windows 2022
henrymercer Mar 21, 2022
5d72058
Merge branch 'main' into aeisenberg/timeout-45-min
henrymercer Mar 21, 2022
81bfc28
Merge pull request #989 from github/henrymercer/update-readme
henrymercer Mar 21, 2022
c3010cb
Status reporting: fix codeql_version field name
cklin Mar 23, 2022
c9973ef
Merge pull request #992 from cklin/fix-codeql-version-field
cklin Mar 23, 2022
686c3a3
Merge branch 'main' into aeisenberg/timeout-45-min
aeisenberg Mar 24, 2022
b887a2c
Merge pull request #976 from aeisenberg/aeisenberg/timeout-45-min
aeisenberg Mar 24, 2022
fb22523
Bump minimist from 1.2.5 to 1.2.6
dependabot[bot] Mar 24, 2022
ca5ed24
Update checked-in dependencies
invalid-email-address Mar 24, 2022
2a7a517
Remove unused `repository_dispatch` trigger
henrymercer Mar 17, 2022
b386fd4
Parameterize release branch workflow over source and target branches
henrymercer Mar 17, 2022
81827d3
Use the person triggering the release workflow as the conductor
henrymercer Mar 17, 2022
ccda44c
Handle missing author information when generating changelog
henrymercer Mar 17, 2022
33f749f
Set up `main -> v2`, `v2 -> v1`, and `v2 -> main` merges
henrymercer Mar 17, 2022
d76b182
Add functionality for `v2 -> v1` backports
henrymercer Mar 17, 2022
4b465cb
Dump environment and GitHub context
henrymercer Mar 22, 2022
b8f3a37
Fix exception when there are no commits to merge
henrymercer Mar 22, 2022
124e7d9
Stop versioning the runner
henrymercer Mar 22, 2022
5fb01dd
Avoid commits with duplicate names during v2 to v1 backport
henrymercer Mar 22, 2022
bd4757c
Update the changelog and version number in a single commit
henrymercer Mar 22, 2022
1668e0a
Only mention merging the mergeback PR in the checklist when relevant
henrymercer Mar 22, 2022
0b037b4
Add merging the v1 release PR to the checklist
henrymercer Mar 23, 2022
f143182
Add "Update dependencies" label to v1 release PR
henrymercer Mar 23, 2022
3359990
Avoid conflicts by reverting 1.x version num commit from last v1 release
henrymercer Mar 23, 2022
da7944b
Update release process doc
henrymercer Mar 24, 2022
df16470
Merge pull request #993 from github/dependabot/npm_and_yarn/minimist-…
henrymercer Mar 24, 2022
85cfdb2
Don't download packs when it isn't needed
edoardopirovano Mar 25, 2022
6e57bba
Merge pull request #998 from github/edoardo/no-download-pack
edoardopirovano Mar 25, 2022
9d26fe0
Use source branch and target branch names consistently
henrymercer Mar 25, 2022
bed132d
Use a more restrictive `sed` pattern
henrymercer Mar 25, 2022
d0bd808
Expose a more restrictive interface to the release script
henrymercer Mar 25, 2022
f784647
Merge branch 'main' into henrymercer/update-release-process
henrymercer Mar 25, 2022
044f112
Update branch protection instructions
henrymercer Mar 25, 2022
d068f53
Fix failing tests
aeisenberg Mar 1, 2022
88db5e7
Merge branch 'main' into aeisenberg/checkout-path-commitoid
aeisenberg Mar 25, 2022
6d1f0a0
Merge pull request #956 from github/aeisenberg/checkout-path-commitoid
aeisenberg Mar 25, 2022
839aa81
Merge branch 'main' into henrymercer/update-release-process
henrymercer Mar 25, 2022
4d6e9c0
Merge pull request #995 from github/henrymercer/update-release-process
henrymercer Mar 25, 2022
077ec09
#996: Fix python_setup/install_tool.sh
cdivitotawela Mar 25, 2022
d625a00
Start running ATM queries again
edoardopirovano Mar 25, 2022
3d23aad
Use Node.js v16 in all Actions
henrymercer Feb 3, 2022
b949e49
Upgrade Node type definitions
henrymercer Feb 3, 2022
43c9f26
Bump version to 2.1.6
henrymercer Mar 22, 2022
9a709c1
Add changelog note
henrymercer Mar 28, 2022
45b96c3
Add PR check to validate compatibility with Node 12
henrymercer Mar 28, 2022
9e40359
Improve code comments
henrymercer Mar 28, 2022
0ed0799
Merge pull request #999 from github/edoardo/reenable-atm
edoardopirovano Mar 28, 2022
63b2636
Merge branch 'main' into python2-fix
RasmusWL Mar 29, 2022
01c7223
Add v2 only prefix to changelog note
henrymercer Mar 29, 2022
c22162c
Merge branch 'main' into henrymercer/bump-node-js-to-v16
henrymercer Mar 29, 2022
fdc2a90
Merge pull request #997 from cdivitotawela/python2-fix
edoardopirovano Mar 29, 2022
eea7cf1
Merge branch 'main' into henrymercer/bump-node-js-to-v16
henrymercer Mar 29, 2022
8237e85
Merge pull request #1000 from github/henrymercer/bump-node-js-to-v16
henrymercer Mar 29, 2022
2f4dd4b
Use `git add --all .`
henrymercer Mar 29, 2022
73ba7ff
Merge branch 'main' into henrymercer/pr-check-validate-node-12-build
henrymercer Mar 29, 2022
f0e2f3c
Merge pull request #1001 from github/henrymercer/pr-check-validate-no…
henrymercer Mar 29, 2022
282b607
Update changelog rewriting step to match v2+ only release notes
henrymercer Mar 29, 2022
af34c6d
Merge pull request #1002 from github/henrymercer/update-changelog-rew…
henrymercer Mar 29, 2022
f1060fb
Bump default CodeQL version to 2.8.4
edoardopirovano Mar 21, 2022
d8576e3
Merge pull request #990 from github/edoardo/2.8.4-bump
edoardopirovano Mar 29, 2022
1d58cc1
Fix typos in release workflow
edoardopirovano Mar 30, 2022
bfe9e81
Merge pull request #1003 from github/edoardo/fix-workflow
edoardopirovano Mar 30, 2022
8833977
Update changelog for v2.1.6
invalid-email-address Mar 30, 2022
34a1681
Fix location of changelog entry
edoardopirovano Mar 30, 2022
a4da970
Run workflow also on `v2` branch
edoardopirovano Mar 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
201 changes: 147 additions & 54 deletions .github/update-release-branch.py
@@ -1,12 +1,9 @@
import argparse
import datetime
from github import Github
import random
import requests
import subprocess
import sys
import json
import datetime
import os
import subprocess

EMPTY_CHANGELOG = """# CodeQL Action and CodeQL Runner Changelog

Expand All @@ -16,12 +13,12 @@

"""

# The branch being merged from.
# This is the one that contains day-to-day development work.
MAIN_BRANCH = 'main'
# The branch being merged into.
# This is the release branch that users reference.
LATEST_RELEASE_BRANCH = 'v1'
# Value of the mode flag for a v1 release
V1_MODE = 'v1-release'

# Value of the mode flag for a v2 release
V2_MODE = 'v2-release'

# Name of the remote
ORIGIN = 'origin'

Expand All @@ -38,8 +35,8 @@ def run_git(*args):
def branch_exists_on_remote(branch_name):
return run_git('ls-remote', '--heads', ORIGIN, branch_name).strip() != ''

# Opens a PR from the given branch to the release branch
def open_pr(repo, all_commits, short_main_sha, branch_name):
# Opens a PR from the given branch to the target branch
def open_pr(repo, all_commits, source_branch_short_sha, new_branch_name, source_branch, target_branch, conductor, is_v2_release, labels):
# Sort the commits into the pull requests that introduced them,
# and any commits that don't have a pull request
pull_requests = []
Expand All @@ -61,9 +58,8 @@ def open_pr(repo, all_commits, short_main_sha, branch_name):

# Start constructing the body text
body = []
body.append('Merging ' + short_main_sha + ' into ' + LATEST_RELEASE_BRANCH)
body.append('Merging ' + source_branch_short_sha + ' into ' + target_branch)

conductor = get_conductor(repo, pull_requests, commits_without_pull_requests)
body.append('')
body.append('Conductor for this PR is @' + conductor)

Expand All @@ -80,43 +76,40 @@ def open_pr(repo, all_commits, short_main_sha, branch_name):
body.append('')
body.append('Contains the following commits not from a pull request:')
for commit in commits_without_pull_requests:
body.append('- ' + commit.sha + ' - ' + get_truncated_commit_message(commit) + ' (@' + commit.author.login + ')')
author_description = ' (@' + commit.author.login + ')' if commit.author is not None else ''
body.append('- ' + commit.sha + ' - ' + get_truncated_commit_message(commit) + author_description)

body.append('')
body.append('Please review the following:')
body.append(' - [ ] The CHANGELOG displays the correct version and date.')
body.append(' - [ ] The CHANGELOG includes all relevant, user-facing changes since the last release.')
body.append(' - [ ] There are no unexpected commits being merged into the ' + LATEST_RELEASE_BRANCH + ' branch.')
body.append(' - [ ] There are no unexpected commits being merged into the ' + target_branch + ' branch.')
body.append(' - [ ] The docs team is aware of any documentation changes that need to be released.')
body.append(' - [ ] The mergeback PR is merged back into ' + MAIN_BRANCH + ' after this PR is merged.')
if is_v2_release:
body.append(' - [ ] The mergeback PR is merged back into ' + source_branch + ' after this PR is merged.')
body.append(' - [ ] The v1 release PR is merged after this PR is merged.')

title = 'Merge ' + MAIN_BRANCH + ' into ' + LATEST_RELEASE_BRANCH
title = 'Merge ' + source_branch + ' into ' + target_branch

# Create the pull request
# PR checks won't be triggered on PRs created by Actions. Therefore mark the PR as draft so that
# a maintainer can take the PR out of draft, thereby triggering the PR checks.
pr = repo.create_pull(title=title, body='\n'.join(body), head=branch_name, base=LATEST_RELEASE_BRANCH, draft=True)
pr = repo.create_pull(title=title, body='\n'.join(body), head=new_branch_name, base=target_branch, draft=True)
pr.add_to_labels(*labels)
print('Created PR #' + str(pr.number))

# Assign the conductor
pr.add_to_assignees(conductor)
print('Assigned PR to ' + conductor)

# Gets the person who should be in charge of the mergeback PR
def get_conductor(repo, pull_requests, other_commits):
# If there are any PRs then use whoever merged the last one
if len(pull_requests) > 0:
return get_merger_of_pr(repo, pull_requests[-1])

# Otherwise take the author of the latest commit
return other_commits[-1].author.login

# Gets a list of the SHAs of all commits that have happened on main
# since the release branched off.
# This will not include any commits that exist on the release branch
# that aren't on main.
def get_commit_difference(repo):
commits = run_git('log', '--pretty=format:%H', ORIGIN + '/' + LATEST_RELEASE_BRANCH + '..' + ORIGIN + '/' + MAIN_BRANCH).strip().split('\n')
# Gets a list of the SHAs of all commits that have happened on the source branch
# since the last release to the target branch.
# This will not include any commits that exist on the target branch
# that aren't on the source branch.
def get_commit_difference(repo, source_branch, target_branch):
# Passing split nothing means that the empty string splits to nothing: compare `''.split() == []`
# to `''.split('\n') == ['']`.
commits = run_git('log', '--pretty=format:%H', ORIGIN + '/' + target_branch + '..' + ORIGIN + '/' + source_branch).strip().split()

# Convert to full-fledged commit objects
commits = [repo.get_commit(c) for c in commits]
Expand All @@ -136,7 +129,7 @@ def get_truncated_commit_message(commit):
else:
return message

# Converts a commit into the PR that introduced it to the main branch.
# Converts a commit into the PR that introduced it to the source branch.
# Returns the PR object, or None if no PR could be found.
def get_pr_for_commit(repo, commit):
prs = commit.get_pulls()
Expand Down Expand Up @@ -179,29 +172,69 @@ def update_changelog(version):


def main():
if len(sys.argv) != 3:
raise Exception('Usage: update-release.branch.py <github token> <repository nwo>')
github_token = sys.argv[1]
repository_nwo = sys.argv[2]
parser = argparse.ArgumentParser('update-release-branch.py')

parser.add_argument(
'--github-token',
type=str,
required=True,
help='GitHub token, typically from GitHub Actions.'
)
parser.add_argument(
'--repository-nwo',
type=str,
required=True,
help='The nwo of the repository, for example github/codeql-action.'
)
parser.add_argument(
'--mode',
type=str,
required=True,
choices=[V2_MODE, V1_MODE],
help=f"Which release to perform. '{V2_MODE}' uses main as the source branch and v2 as the target branch. " +
f"'{V1_MODE}' uses v2 as the source branch and v1 as the target branch."
)
parser.add_argument(
'--conductor',
type=str,
required=True,
help='The GitHub handle of the person who is conducting the release process.'
)

args = parser.parse_args()

if args.mode == V2_MODE:
source_branch = 'main'
target_branch = 'v2'
elif args.mode == V1_MODE:
source_branch = 'v2'
target_branch = 'v1'
else:
raise ValueError(f"Unexpected value for release mode: '{args.mode}'")

repo = Github(github_token).get_repo(repository_nwo)
repo = Github(args.github_token).get_repo(args.repository_nwo)
version = get_current_version()

if args.mode == V1_MODE:
# Change the version number to a v1 equivalent
version = get_current_version()
version = f'1{version[1:]}'

# Print what we intend to go
print('Considering difference between ' + MAIN_BRANCH + ' and ' + LATEST_RELEASE_BRANCH)
short_main_sha = run_git('rev-parse', '--short', ORIGIN + '/' + MAIN_BRANCH).strip()
print('Current head of ' + MAIN_BRANCH + ' is ' + short_main_sha)
print('Considering difference between ' + source_branch + ' and ' + target_branch)
source_branch_short_sha = run_git('rev-parse', '--short', ORIGIN + '/' + source_branch).strip()
print('Current head of ' + source_branch + ' is ' + source_branch_short_sha)

# See if there are any commits to merge in
commits = get_commit_difference(repo)
commits = get_commit_difference(repo=repo, source_branch=source_branch, target_branch=target_branch)
if len(commits) == 0:
print('No commits to merge from ' + MAIN_BRANCH + ' to ' + LATEST_RELEASE_BRANCH)
print('No commits to merge from ' + source_branch + ' to ' + target_branch)
return

# The branch name is based off of the name of branch being merged into
# and the SHA of the branch being merged from. Thus if the branch already
# exists we can assume we don't need to recreate it.
new_branch_name = 'update-v' + version + '-' + short_main_sha
new_branch_name = 'update-v' + version + '-' + source_branch_short_sha
print('Branch name is ' + new_branch_name)

# Check if the branch already exists. If so we can abort as this script
Expand All @@ -212,19 +245,79 @@ def main():

# Create the new branch and push it to the remote
print('Creating branch ' + new_branch_name)
run_git('checkout', '-b', new_branch_name, ORIGIN + '/' + MAIN_BRANCH)

print('Updating changelog')
update_changelog(version)
if args.mode == V1_MODE:
# If we're performing a backport, start from the v1 branch
print(f'Creating {new_branch_name} from the {ORIGIN}/v1 branch')
run_git('checkout', '-b', new_branch_name, f'{ORIGIN}/v1')

# Revert the commit that we made as part of the last release that updated the version number and
# changelog to refer to 1.x.x variants. This avoids merge conflicts in the changelog and
# package.json files when we merge in the v2 branch.
# This commit will not exist the first time we release the v1 branch from the v2 branch, so we
# use `git log --grep` to conditionally revert the commit.
print('Reverting the 1.x.x version number and changelog updates from the last release to avoid conflicts')
v1_update_commits = run_git('log', '--grep', '^Update version and changelog for v', '--format=%H').split()

if len(v1_update_commits) > 0:
print(f' Reverting {v1_update_commits[0]}')
# Only revert the newest commit as older ones will already have been reverted in previous
# releases.
run_git('revert', v1_update_commits[0], '--no-edit')

# Also revert the "Update checked-in dependencies" commit created by Actions.
update_dependencies_commit = run_git('log', '--grep', '^Update checked-in dependencies', '--format=%H').split()[0]
print(f' Reverting {update_dependencies_commit}')
run_git('revert', update_dependencies_commit, '--no-edit')

else:
print(' Nothing to revert.')

print(f'Merging {ORIGIN}/{source_branch} into the release prep branch')
run_git('merge', f'{ORIGIN}/{source_branch}', '--no-edit')

# Migrate the package version number from a v2 version number to a v1 version number
print(f'Setting version number to {version}')
subprocess.run(['npm', 'version', version, '--no-git-tag-version'])
run_git('add', 'package.json', 'package-lock.json')

# Migrate the changelog notes from v2 version numbers to v1 version numbers
print('Migrating changelog notes from v2 to v1')
subprocess.run(['sed', '-i', 's/^## 2\./## 1./g', 'CHANGELOG.md'])

# Remove changelog notes from v2 that don't apply to v1
subprocess.run(['sed', '-i', '/^- \[v2+ only\]/d', 'CHANGELOG.md'])

# Amend the commit generated by `npm version` to update the CHANGELOG
run_git('add', 'CHANGELOG.md')
run_git('commit', '-m', f'Update version and changelog for v{version}')
else:
# If we're performing a standard release, there won't be any new commits on the target branch,
# as these will have already been merged back into the source branch. Therefore we can just
# start from the source branch.
run_git('checkout', '-b', new_branch_name, f'{ORIGIN}/{source_branch}')

print('Updating changelog')
update_changelog(version)

# Create a commit that updates the CHANGELOG
run_git('add', 'CHANGELOG.md')
run_git('commit', '-m', version)
# Create a commit that updates the CHANGELOG
run_git('add', 'CHANGELOG.md')
run_git('commit', '-m', f'Update changelog for v{version}')

run_git('push', ORIGIN, new_branch_name)

# Open a PR to update the branch
open_pr(repo, commits, short_main_sha, new_branch_name)
open_pr(
repo,
commits,
source_branch_short_sha,
new_branch_name,
source_branch=source_branch,
target_branch=target_branch,
conductor=args.conductor,
is_v2_release=args.mode == V2_MODE,
labels=['Update dependencies'] if args.mode == V1_MODE else [],
)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion .github/workflows/__analyze-ref-input.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__debug-artifacts.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__extractor-ram-threads.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__go-custom-queries.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__go-custom-tracing-autobuild.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__go-custom-tracing.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__javascript-source-root.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__multi-language-autodetect.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__packaging-config-inputs-js.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__packaging-config-js.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/__packaging-inputs-js.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.