-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.py
153 lines (143 loc) · 6.79 KB
/
action.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from github import Github, GithubException
import base64
import os
import pandas as pd
def create_or_update_file(repo_handle, path, content):
try:
repo_handle.create_file(
path=path,
content=content,
message=f"add {path}"
)
print(f"successfully created {path}")
except GithubException as e:
cf = repo_handle.get_contents(path)
sha = cf.sha
content_remote = (
base64.b64decode(bytes(cf.content, "utf-8")).decode("utf-8")
)
if content == content_remote:
print(f"no change detected in {path}; {e}")
else:
repo_handle.update_file(
path=path,
content=content,
sha=sha,
message=f"update {path}"
)
print(f"successfully updated {path}")
if __name__ == "__main__":
GITHUB_WORKSPACE = "/github/workspace"
GITHUB = Github(os.environ["PAT"])
FILE_PATH = os.environ["FILE_PATH"]
ORG = os.environ["ORG"]
df = pd.read_csv(os.path.join(GITHUB_WORKSPACE, FILE_PATH))
df = df[df["autogenerate"] == 1]
repos = [f"observatory-{obs.lower()}-crate" for obs in df["EMOBON_observatory_id"]]
water_urls = [url for url in df["Water Column"]]
sediment_urls = [url for url in df["Soft sediment"]]
data_quality_control_threshold_dates = [date for date in df["data_quality_control_threshold_date"]]
data_quality_control_assignees = [assignee for assignee in df["data_quality_control_assignee"]]
rocrate_profile_uris = [uri for uri in df["rocrate_profile_uri"]]
for repo, water_url, sediment_url, data_quality_control_threshold_date, data_quality_control_assignee, rocrate_profile_uri in zip(repos, water_urls, sediment_urls, data_quality_control_threshold_dates, data_quality_control_assignees, rocrate_profile_uris):
print(f">>> {repo}")
# create repo
try:
GITHUB.get_organization(ORG).create_repo(repo)
print(f"successfully created {repo}")
except GithubException as e:
print(f"failed to create {repo}; {e}")
# acquire reference to repo
repo_handle = GITHUB.get_organization(ORG).get_repo(repo)
# populate repo with README.md
path = "./README.md"
content = (
f"# {repo}\n"
"This repository is an RO-Crate containing the harvested EMO BON logsheets for this observatory, along with their representation as linked data.\n"
)
create_or_update_file(repo_handle, path, content)
# populate repo with workflow.yml
path = "./.github/workflows/workflow.yml"
content = (
"name: linked-data-etl\n"
"on:\n"
" workflow_dispatch:\n"
" schedule:\n"
" - cron: '0 0 1 */6 *'\n"
"jobs:\n"
" job:\n"
" runs-on: ubuntu-latest\n"
" env:\n"
f" ROCRATE_PROFILE_URI: {rocrate_profile_uri}\n"
" steps:\n"
" - name: checkout\n"
" uses: actions/checkout@v3\n"
" - name: download\n"
" uses: emo-bon/logsheet-downloader-action@master\n"
" - name: git-auto-commit-action\n"
" uses: stefanzweifel/git-auto-commit-action@v5\n"
" with:\n"
" commit_message: update on behalf of logsheet-downloader-action\n"
" - name: data-quality-control-action\n"
" uses: emo-bon/data-quality-control-action@main\n"
" env:\n"
" PAT: ${{ secrets.GITHUB_TOKEN }}\n"
" REPO: ${{ github.repository }}\n"
f" ASSIGNEE: {data_quality_control_assignee}\n"
" - name: git-auto-commit-action\n"
" uses: stefanzweifel/git-auto-commit-action@v5\n"
" with:\n"
" commit_message: update on behalf of data-quality-control-action\n"
" - name: rocrate-sembench-setup\n"
" uses: vliz-be-opsci/rocrate-sembench-setup@main\n"
" env:\n"
" PROFILE: ${{ env.ROCRATE_PROFILE_URI }}\n"
" - name: semantify\n"
" uses: vliz-be-opsci/semantify@main\n"
" - name: rocrate-sembench-cleanup\n"
" run: sudo rm -rf ~sembench_data_cache/ ~sembench_kwargs.json\n"
" - name: git-auto-commit-action\n"
" uses: stefanzweifel/git-auto-commit-action@v5\n"
" with:\n"
" commit_message: update on behalf of semantify\n"
" - name: rocrate-metadata-generator-action\n"
" uses: emo-bon/rocrate-metadata-generator-action@main\n"
" env:\n"
" PROFILE: ${{ env.ROCRATE_PROFILE_URI }}\n"
" REPO: ${{ github.repository }}\n"
" - name: git-auto-commit-action\n"
" uses: stefanzweifel/git-auto-commit-action@v5\n"
" with:\n"
" commit_message: update on behalf of rocrate-metadata-generator-action\n"
" - name: rdf-aggregate-action\n"
" uses: vliz-be-opsci/rdf-aggregate-action@main\n"
" env:\n"
" GLOBS: sediment/**/*:ttl|water/**/*:ttl|ro-crate-metadata.json:json-ld\n"
" - name: git-auto-commit-action\n"
" uses: stefanzweifel/git-auto-commit-action@v5\n"
" with:\n"
" commit_message: update on behalf of rdf-aggregate-action\n"
" - name: rocrate-to-pages\n"
" uses: vliz-be-opsci/rocrate-to-pages@latest\n"
" with:\n"
" multiple_rocrates: true\n"
" release_management: false\n"
" include_draft: false\n"
" index_html: false\n"
" space_to_pages_homepage: https://data.emobon.embrc.eu\n"
" - name: actions-gh-pages\n"
" uses: peaceiris/actions-gh-pages@v3\n"
" with:\n"
" github_token: ${{ secrets.GITHUB_TOKEN }}\n"
" publish_dir: ./unicornpages\n"
)
create_or_update_file(repo_handle, path, content)
# populate repo with workflow_properties.yml
path = "./config/workflow_properties.yml"
content = (
f"water: {water_url}\n"
f"sediment: {sediment_url}\n"
f"data_quality_control_threshold_date: {data_quality_control_threshold_date}\n"
)
create_or_update_file(repo_handle, path, content)
print()