-
Notifications
You must be signed in to change notification settings - Fork 3
/
kg-microbe.Makefile
107 lines (98 loc) · 3.77 KB
/
kg-microbe.Makefile
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
# Define variables
RUNNER_VERSION := 2.317.0
RUNNER_URL := https://github.com/actions/runner/releases/download/v$(RUNNER_VERSION)/actions-runner-linux-x64-$(RUNNER_VERSION).tar.gz
RUNNER_DIR := actions-runner
REPO_OWNER := Knowledge-Graph-Hub
REPO_NAME := kg-microbe
REPO_URL := https://github.com/$(REPO_OWNER)/$(REPO_NAME)
TOKEN := $(GH_TOKEN)
MERGED_TARBALL := data_merged.tar.gz
PART_SIZE := 2000M # Size of each part (less than 2GB)
# Detect OS and set STAT_CMD accordingly
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
STAT_CMD = stat -c %s
else ifeq ($(UNAME_S),Darwin)
STAT_CMD = stat -f %z
endif
.PHONY: release pre-release tag generate-tarballs check-and-split
release: generate-tarballs
@$(call create_release,release)
pre-release: generate-tarballs
@$(call create_release,pre-release)
tag: generate-tarballs
@$(call create_tag)
generate-tarballs:
@echo "Generating tarballs of the specified directories..."
@for dir in data/transformed/*; do \
if [ -d "$$dir" ]; then \
if [ $$(find $$dir -type f | wc -l) -gt 0 ]; then \
tarball_name=$$(basename $$dir).tar.gz; \
tar -czvf $$tarball_name -C $$dir .; \
echo "Tarball generated successfully as $$tarball_name."; \
$(MAKE) check-and-split TARFILE=$$tarball_name DIR=$$dir; \
else \
echo "Directory $$dir is empty. Skipping tarball generation."; \
fi \
fi \
done
@if [ -f data/merged/merged-kg.tar.gz ]; then \
cp data/merged/merged-kg.tar.gz $(MERGED_TARBALL); \
echo "Merged tarball copied successfully."; \
$(MAKE) check-and-split TARFILE=$(MERGED_TARBALL) DIR=data/merged; \
else \
echo "Merged tarball does not exist. Skipping."; \
fi
@echo "Tarballs generated successfully."
check-and-split:
@echo "Checking if $(TARFILE) needs to be split..."
@if [ $$($(STAT_CMD) "$(TARFILE)") -gt 2147483648 ]; then \
echo "$(TARFILE) is larger than 2GB. Tarballing individual files..."; \
dirname=$$(basename $(DIR)); \
for file in $(DIR)/*; do \
if [ -f "$$file" ]; then \
filename=$$(basename $$file); \
tarball_name=$${dirname}_$${filename}.tar.gz; \
tar -czvf $$tarball_name -C $$(dirname $$file) $$(basename $$file); \
echo "Tarball generated successfully as $$tarball_name."; \
else \
echo "$$file is not a regular file. Skipping."; \
fi \
done; \
rm -f $(TARFILE); \
echo "$(TARFILE) deleted after splitting."; \
else \
echo "$(TARFILE) is less than 2GB. No need to split."; \
fi
define create_release
@echo "Creating a $(1) on GitHub..."
@read -p "Enter $(1) tag (e.g., $(shell date +%Y-%m-%d)): " TAG_NAME; \
read -p "Enter $(1) title: " RELEASE_TITLE; \
read -p "Enter $(1) notes: " RELEASE_NOTES; \
if git rev-parse "$$TAG_NAME" >/dev/null 2>&1; then \
echo "Error: Tag '$$TAG_NAME' already exists. Please choose a different tag."; \
exit 1; \
fi; \
git tag -a $$TAG_NAME -m "$$RELEASE_TITLE"; \
git push origin $$TAG_NAME; \
gh release create $$TAG_NAME --title "$$RELEASE_TITLE" --notes "$$RELEASE_NOTES" $(if $(filter $(1),pre-release),--prerelease) --repo $(REPO_OWNER)/$(REPO_NAME); \
for tarball in *.tar.gz; do \
gh release upload $$TAG_NAME $$tarball --repo $(REPO_OWNER)/$(REPO_NAME); \
done; \
rm -f *.tar.gz; \
echo "$(capitalize $(1)) $$TAG_NAME created successfully."
endef
define create_tag
@echo "Creating a release on GitHub..."
@read -p "Enter release tag (e.g., $(shell date +%Y-%m-%d)): " TAG; \
read -p "Enter release title: " RELEASE_TITLE; \
read -p "Enter release notes: " RELEASE_NOTES; \
git tag -a $$TAG -m "$$RELEASE_TITLE"; \
git push origin $$TAG; \
for tarball in *.tar.gz; do \
gh release upload $$TAG $$tarball --repo $(REPO_OWNER)/$(REPO_NAME); \
done; \
rm -f *.tar.gz; \
echo "Release $$TAG created successfully."
endef
capitalize = $(subst $(1),$(shell echo $(1) | tr '[:lower:]' '[:upper:]'),$(1))