Skip to content

Commit

Permalink
ci: Add workflow for guards deprecation
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <ryan@synca.io>
  • Loading branch information
phlax committed Oct 14, 2024
1 parent 34838db commit 624c49e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/envoy-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ on:
options:
- create-release
- sync-version-histories
- deprecate-versions
pr:
type: boolean
default: true
Expand Down Expand Up @@ -175,6 +176,27 @@ jobs:
${{ steps.checkout.outputs.branch-name != 'main' && format('[{0}]', steps.checkout.outputs.branch-name) || '' }}
repo: Sync version histories
deprecate_versions:
runs-on: ubuntu-22.04
if: github.event_name == 'workflow_dispatch' && inputs.task == 'deprecate-versions'
name: Deprecate versions
steps:
- id: appauth
name: App auth
uses: envoyproxy/toolshed/gh-actions/appauth@actions-v0.2.36
with:
app_id: ${{ secrets.ENVOY_CI_PUBLISH_APP_ID }}
key: ${{ secrets.ENVOY_CI_PUBLISH_APP_KEY }}
- id: checkout
name: Checkout Envoy repository
uses: envoyproxy/toolshed/gh-actions/github/checkout@actions-v0.2.36
with:
config: |
fetch-depth: 0
- name: Run deprecation tool
run: |
bazel run --config=ci //tools/deprecate_guards -- --dry-run
## Triggered actions
# On release to `main`:
Expand Down
1 change: 1 addition & 0 deletions tools/deprecate_guards/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ py_binary(
srcs = ["deprecate_guards.py"],
deps = [
"@envoy_repo",
requirement("aio.run.runner"),
requirement("gitpython"),
requirement("pygithub"),
],
Expand Down
54 changes: 37 additions & 17 deletions tools/deprecate_guards/deprecate_guards.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@

import envoy_repo

try:
input = raw_input # Python 2
except NameError:
pass # Python 3
from aio.run import runner


ENVOY_REPO = "envoyproxy/envoy"
# Tag issues created with these labels.
LABELS = ['deprecation', 'tech debt', 'no stalebot']

Expand All @@ -44,15 +43,15 @@ def get_confirmation():
return input('Creates issues? [yN] ').strip().lower() in ('y', 'yes')


def create_issues(access_token, runtime_and_pr):
def create_issues(repo, access_token, runtime_and_pr):
"""Create issues in GitHub for code to clean up old runtime guarded features.
Args:
access_token: GitHub access token (see comment at top of file).
runtime_and_pr: a list of runtime guards and the PRs and commits they were added.
"""
git = github.Github(access_token)
repo = git.get_repo('envoyproxy/envoy')
repo = git.get_repo(repo)

# Find GitHub label objects for LABELS.
labels = []
Expand Down Expand Up @@ -186,17 +185,38 @@ def get_runtime_and_pr():
sys.exit(1)


if __name__ == '__main__':
runtime_and_pr = get_runtime_and_pr()
class DeprecationRunner(runner.Runner):

def add_arguments(self, parser):
super().add_arguments(parser)
parser.add_argument("--dry-run", action="store_true")
parser.add_argument("--repo", default=ENVOY_REPO)

async def run(self):
runtime_and_pr = get_runtime_and_pr()

if not runtime_and_pr:
print('No code is deprecated.')
return

if not runtime_and_pr:
print('No code is deprecated.')
sys.exit(0)
if self.args.dry_run:
for item in runtime_and_pr:
print(item)
return

access_token = os.getenv('GITHUB_TOKEN')
if not access_token:
print(
'Missing GITHUB_TOKEN: see instructions in tools/deprecate_guards/deprecate_guards.py')
sys.exit(1)
access_token = os.getenv('GITHUB_TOKEN')
if not access_token:
print(
'Missing GITHUB_TOKEN: see instructions in tools/deprecate_guards/deprecate_guards.py'
)
return 1

create_issues(access_token, runtime_and_pr)
create_issues(access_token, runtime_and_pr)


def main(*args):
return DeprecationRunner(*args)()


if __name__ == '__main__':
sys.exit(main(*sys.argv[1:]))

0 comments on commit 624c49e

Please sign in to comment.