Properly handle the file list for updating the dashboard. (#11282)
Also add slightly nicer logging.
Austin S. Hemmelgarn committed
Jul 14, 2021 at 12:42 UTC
a08c1b4af37b319af551e446ff8702b1597e3cd0
2 files changed
+23
-5
.github/workflows/dashboard-pr.yml
+1
-3
@@ -36,9 +36,7 @@ jobs:
36
env:
37
GH_TOKEN: ${{ secrets.NETDATABOT_GITHUB_TOKEN }}
38
with:
39
- files: |
40
- packaging/dashboard.version
41
- packaging/dashboard.checksums
39
+ files: ${{ env.COMMIT_FILES }} # Created by the bundle_dashboard.py script.
40
commit-message: 'Update dashboard to version ${{ github.event.inputs.dashboard_version }}.'
41
ref: refs/heads/dashboard-${{ github.event.inputs.dashboard_version }}
42
- name: Create PR
web/gui/bundle_dashboard.py
+22
-2
@@ -2,7 +2,9 @@
2
#
3
# Copyright: © 2021 Netdata Inc.
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
-'''Bundle the dashboard code into the agent repo.'''
5
+'''Bundle the dashboard code into the agent repo.
6
+
7
+ This is designed to be run as part of a GHA workflow, but will work fine outside of one.'''
8
9
import os
10
import shutil
@@ -69,12 +71,19 @@ dist_webstaticmedia_DATA = \\
71
72
def copy_dashboard(tag):
73
'''Fetch and bundle the dashboard code.'''
74
+ print('Preparing target directory')
75
shutil.rmtree(BASEPATH)
76
BASEPATH.mkdir()
77
+ print('::group::Fetching dashboard release tarball')
78
subprocess.check_call('curl -L -o dashboard.tar.gz ' + URLTEMPLATE.format(tag), shell=True)
79
+ print('::endgroup::')
80
+ print('::group::Extracting dashboard release tarball')
81
subprocess.check_call('tar -xvzf dashboard.tar.gz -C ' + str(BASEPATH) + ' --strip-components=1', shell=True)
82
+ print('::endgroup::')
83
+ print('Copying README.md')
84
BASEPATH.joinpath('README.md').symlink_to('../.dashboard-notice.md')
77
-# BASEPATH.joinpath('..', 'dashboard.tar.gz').unlink()
85
+ print('Removing dashboard release tarball')
86
+ BASEPATH.joinpath('..', 'dashboard.tar.gz').unlink()
87
88
89
def genfilelist(path):
@@ -87,6 +96,7 @@ def genfilelist(path):
96
97
def write_makefile():
98
'''Write out the makefile for the dashboard code.'''
99
+ print('Generating Makefile')
100
MAKEFILEDATA = MAKEFILETEMPLATE.format(
101
genfilelist(BASEPATH),
102
genfilelist(BASEPATH.joinpath('css')),
@@ -101,5 +111,15 @@ def write_makefile():
111
BASEPATH.joinpath('Makefile.am').write_text(MAKEFILEDATA)
112
113
114
+def list_changed_files():
115
+ '''Create a list of changed files, and set it in an environment variable.'''
116
+ if 'GITHUB_ENV' in os.environ:
117
+ print('Generating file list for commit.')
118
+ subprocess.check_call('echo "COMMIT_FILES<<EOF" >> $GITHUB_ENV', shell=True)
119
+ subprocess.check_call('git status --porcelain=v1 --no-renames --untracked-files=all | rev | cut -d \' \' -f 1 | rev >> $GITHUB_ENV', shell=True)
120
+ subprocess.check_call('echo "EOF" >> $GITHUB_ENV', shell=True)
121
+
122
+
123
copy_dashboard(sys.argv[1])
124
write_makefile()
125
+list_changed_files()