Skip to content

Commit 5280ce6

Browse files
authored
Merge pull request #29 from bmwcarit/auto-release-tutorials
Automatically release archived versions of tutorials
2 parents 7f718a4 + ddfe33c commit 5280ce6

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

.github/package.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-License-Identifier: MPL-2.0
4+
#
5+
# This file is part of Ramses Composer
6+
# (see https://github.com/bmwcarit/ramses-composer-docs).
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
9+
# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
11+
from pathlib import Path
12+
import shutil
13+
import os
14+
import sys
15+
import subprocess
16+
import re
17+
18+
19+
def get_git_files(path):
20+
"""Get all files known to git"""
21+
cmd = ['git', 'ls-files', '-z']
22+
files = [f.decode('utf-8') for f in subprocess.check_output(cmd, cwd=path).split(b'\0') if f]
23+
return files
24+
25+
26+
def filter_includes_excludes(iterable, *, includes=['.*'], excludes=[]):
27+
key_fun = (lambda e: e)
28+
include_re = re.compile('|'.join([f'(?:{i})'for i in includes]))
29+
exclude_re = re.compile('|'.join([f'(?:{e})'for e in excludes]))
30+
31+
res = []
32+
for e in iterable:
33+
k = key_fun(e)
34+
if includes and include_re.search(k) and not (excludes and exclude_re.search(k)):
35+
res.append(e)
36+
return res
37+
38+
39+
def copy_files(source_root, destination_root, files):
40+
for f in files:
41+
source_path = Path(source_root) / f
42+
destination_path = Path(destination_root) / f
43+
destination_path.parent.mkdir(parents=True, exist_ok=True)
44+
if source_path.is_symlink():
45+
destination_path.unlink(missing_ok=True)
46+
shutil.copy(source_path, destination_path, follow_symlinks=False)
47+
48+
49+
def main():
50+
script_dir = Path(os.path.realpath(os.path.dirname(__file__)))
51+
root_dir = (script_dir / '..').resolve()
52+
target_dir = root_dir / 'release'
53+
target_dir.mkdir(parents=True, exist_ok=True)
54+
55+
source = root_dir
56+
destination = target_dir
57+
58+
tutorials = set()
59+
60+
for root, _dirs, files in os.walk(root_dir):
61+
for file in files:
62+
if file.endswith(".rca"):
63+
tutorial_path = (Path(root) / file).parents[0]
64+
tutorials.add(tutorial_path.relative_to(root_dir))
65+
66+
tutorial_paths = [str(t.as_posix()) for t in tutorials]
67+
include_paths = tutorial_paths + [
68+
'^readme.md',
69+
'^LICENSE.txt',
70+
]
71+
72+
exclude_docs = [str((t / 'docs').as_posix()) for t in tutorials]
73+
exclude_readmes = [str((t / 'README.md').as_posix()) for t in tutorials]
74+
exclude_extra = [
75+
'.git*',
76+
'ramses-composer-logo.png',
77+
]
78+
79+
exclude_paths = exclude_docs + exclude_readmes + exclude_extra
80+
# gather source files
81+
source_files = get_git_files(source)
82+
source_files = filter_includes_excludes(source_files, includes=include_paths, excludes=exclude_paths)
83+
84+
# copy source -> destination
85+
copy_files(source, destination, source_files)
86+
87+
# Create zip archive
88+
archive_name = 'tutorials'
89+
if len(sys.argv) == 2:
90+
archive_name = sys.argv[1]
91+
shutil.make_archive(archive_name, 'zip', destination)
92+
93+
94+
if __name__ == "__main__":
95+
main()

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-License-Identifier: MPL-2.0
2+
#
3+
# This file is part of Ramses Composer
4+
# (see https://github.com/bmwcarit/ramses-composer-docs).
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7+
# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+
name: Release
10+
11+
on:
12+
push:
13+
tags:
14+
- 'v*.*.*'
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
with:
23+
lfs: 'true'
24+
25+
- name: Create archive
26+
shell: bash
27+
run: |
28+
python3 .github/package.py ${{runner.workspace}}/tutorials
29+
30+
- name: Publish release
31+
uses: softprops/action-gh-release@v1
32+
with:
33+
files: |
34+
${{runner.workspace}}/tutorials.zip

0 commit comments

Comments
 (0)