Skip to content

Commit 357529d

Browse files
vmaxGaneshwara Herawan Hananda
authored andcommitted
Bugfix deploy_npm rule (#177)
## What is the goal of this PR? Allow release deployment of NPM packages ## What are the changes implemented in this PR? - Copy unmodified package when deploying release (otherwise `npm` doesn't find it) - refactor: separate old and new filenames or npm archives to constants - chore: remove old Bash implementation of `deploy_npm` - chore: add Apache license header to `npm/templates/BUILD` - chore: regenerate docs
1 parent bd93910 commit 357529d

File tree

4 files changed

+35
-83
lines changed

4 files changed

+35
-83
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ Assemble package for installation with RPM
18921892
## assemble_targz
18931893

18941894
<pre>
1895-
assemble_targz(<a href="#assemble_targz-name">name</a>, <a href="#assemble_targz-output_filename">output_filename</a>, <a href="#assemble_targz-targets">targets</a>, <a href="#assemble_targz-additional_files">additional_files</a>, <a href="#assemble_targz-empty_directories">empty_directories</a>, <a href="#assemble_targz-permissions">permissions</a>, <a href="#assemble_targz-visibility">visibility</a>)
1895+
assemble_targz(<a href="#assemble_targz-name">name</a>, <a href="#assemble_targz-output_filename">output_filename</a>, <a href="#assemble_targz-targets">targets</a>, <a href="#assemble_targz-additional_files">additional_files</a>, <a href="#assemble_targz-empty_directories">empty_directories</a>, <a href="#assemble_targz-permissions">permissions</a>, <a href="#assemble_targz-visibility">visibility</a>, <a href="#assemble_targz-tags">tags</a>)
18961896
</pre>
18971897

18981898
Assemble distribution archive (.tar.gz)
@@ -1969,6 +1969,12 @@ Assemble distribution archive (.tar.gz)
19691969
</p>
19701970
</td>
19711971
</tr>
1972+
<tr id="assemble_targz-tags">
1973+
<td><code>tags</code></td>
1974+
<td>
1975+
optional. default is <code>[]</code>
1976+
</td>
1977+
</tr>
19721978
</tbody>
19731979
</table>
19741980

npm/templates/BUILD

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
119

2-
exports_files(["deploy.py", "deploy.sh"])
20+
exports_files(["deploy.py"])

npm/templates/deploy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import json
2626
import os
2727
import subprocess
28+
import shutil
2829

2930
# usual importing is not possible because
3031
# this script and module with common functions
@@ -43,6 +44,9 @@ def git_commit():
4344
], cwd=os.getenv('BUILD_WORKSPACE_DIRECTORY')).decode().strip()
4445

4546

47+
ORIGINAL_FILENAME = 'deploy_npm.tgz'
48+
MODIFIED_FILENAME = 'deploy_npm_updated.tgz'
49+
4650
parser = argparse.ArgumentParser()
4751
parser.add_argument('repo_type')
4852
args = parser.parse_args()
@@ -118,7 +122,7 @@ def git_commit():
118122

119123
if args.repo_type == 'snapshot':
120124
print('Appending git commit to version')
121-
with tarfile.open('deploy_npm.tgz') as tf, tarfile.open('deploy_npm_updated.tgz', 'w:gz') as tfu:
125+
with tarfile.open(ORIGINAL_FILENAME) as tf, tarfile.open(MODIFIED_FILENAME, 'w:gz') as tfu:
122126
pkg_json_file = tf.extractfile('package/package.json')
123127
pkg_json = json.loads(pkg_json_file.read().decode())
124128
pkg_json['version'] += "-{}".format(git_commit())
@@ -132,12 +136,14 @@ def git_commit():
132136
info.size = content.tell()
133137
content.seek(0)
134138
tfu.addfile(info, content)
139+
else:
140+
shutil.copyfile(ORIGINAL_FILENAME, MODIFIED_FILENAME)
135141

136142
subprocess.check_call([
137143
'npm',
138144
'publish',
139145
'--registry={}'.format(npm_registry),
140-
'deploy_npm_updated.tgz'
146+
MODIFIED_FILENAME
141147
], env={
142148
'PATH': ':'.join([
143149
'/usr/bin/',
@@ -149,4 +155,4 @@ def git_commit():
149155
])
150156
})
151157

152-
os.remove('deploy_npm_updated.tgz')
158+
os.remove(MODIFIED_FILENAME)

npm/templates/deploy.sh

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)