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

Size reports: add a script to streamline workflows #12299

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions .github/workflows/examples-efr32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
cancel-in-progress: true

jobs:
efr32:
name: EFR32
Expand All @@ -30,9 +30,6 @@ jobs:
env:
EFR32_BOARD: BRD4161A
BUILD_TYPE: gn_efr32
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand All @@ -47,15 +44,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
shell: bash
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Bootstrap
timeout-minutes: 25
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/examples-esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ jobs:

env:
BUILD_TYPE: esp32
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand All @@ -48,14 +45,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Bootstrap
timeout-minutes: 25
Expand Down
17 changes: 4 additions & 13 deletions .github/workflows/examples-infineon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ jobs:
name: Infineon examples building
timeout-minutes: 30

env:
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'

Expand All @@ -45,14 +40,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Bootstrap
timeout-minutes: 25
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/examples-k32w.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ jobs:

env:
BUILD_TYPE: gn_k32w
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand All @@ -46,14 +43,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Bootstrap
timeout-minutes: 25
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/examples-linux-standalone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ jobs:

env:
BUILD_TYPE: gn_linux
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand All @@ -47,14 +44,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Bootstrap
timeout-minutes: 10
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/examples-mbed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ jobs:
BUILD_TYPE: mbedos
APP_PROFILE: release
APP_TARGET: CY8CPROTO_062_4343W
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand All @@ -50,14 +47,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Bootstrap
timeout-minutes: 10
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/examples-nrfconnect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ jobs:

env:
BUILD_TYPE: nrfconnect
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand All @@ -47,14 +44,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Bootstrap
timeout-minutes: 25
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/examples-qpg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ jobs:

env:
BUILD_TYPE: gn_qpg
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand All @@ -46,14 +43,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Bootstrap
timeout-minutes: 25
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/examples-telink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ jobs:
name: Telink
env:
BUILD_TYPE: telink
GH_EVENT_PR: ${{ github.event_name == 'pull_request' && github.event.number || 0 }}
GH_EVENT_HASH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
GH_EVENT_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'
Expand All @@ -45,14 +42,10 @@ jobs:
with:
submodules: true

- name: Get parent for size reports
run: |
MERGE_PARENT="$(git --no-pager log -1 --pretty=tformat:%s | sed -n -e 's/Merge [0-9a-f]\+ into //p')"
if test -z "${MERGE_PARENT}" || test "${GH_EVENT_PARENT}" = 0
then
MERGE_PARENT=$GH_EVENT_BASE
fi
echo "GH_EVENT_PARENT=$MERGE_PARENT" >>$GITHUB_ENV
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: scripts/tools/memory/gh_sizes_environment.py "${GH_CONTEXT}"

- name: Build example Telink Lighting App
run: |
Expand Down
55 changes: 55 additions & 0 deletions scripts/tools/memory/gh_sizes_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python3

"""
Set up environment variables used to generate size report artifacts.

Takes a single argument, a JSON dictionary of the `github` context.
Typically run as:

```
- name: Set up environment for size reports
env:
GH_CONTEXT: ${{ toJson(github) }}
run: gh_sizes_environment.py "${GH_CONTEXT}"
```

Sets the following environment variables:

- `GH_EVENT_PR` For a pull request, the PR number; otherwise 0.
- `GH_EVENT_HASH` SHA of the commit under test.
- `GH_EVENT_PARENT` SHA of the parent commit to which the commit under
test is applied.
"""

import json
import os
import re
import subprocess
import sys

github = json.loads(sys.argv[1])

if github['event_name'] == 'pull_request':
pr = github['event']['number']
commit = github['event']['pull_request']['head']['sha']
r = subprocess.run(['git', 'show', '--no-patch', '--format=%s', 'HEAD'],
capture_output=True, text=True, check=True)
m = re.fullmatch('Merge [0-9a-f]+ into ([0-9a-f]+)', r.stdout)
if m:
parent = m.group(1)
else:
parent = github['event']['pull_request']['base']['sha']
else:
pr = 0
commit = github['sha']
parent = github['event']['before']

# Environment variables for subsequent workflow steps are set by
# writing to the file named by `$GITHUB_ENV`.

env = os.environ.get('GITHUB_ENV')
assert env
with open(env, 'at') as out:
print(f'GH_EVENT_PR={pr}', file=out)
print(f'GH_EVENT_HASH={commit}', file=out)
print(f'GH_EVENT_PARENT={parent}', file=out)