-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
152 lines (127 loc) · 5.91 KB
/
makefile
File metadata and controls
152 lines (127 loc) · 5.91 KB
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
###############################################################################
# MULTI-PACKAGE EXPORT SECTION #
###############################################################################
# Dynamically identify all subdirectories (each is treated as a package)
PACKAGES := $(patsubst %/,%,$(wildcard */))
# File extensions to collect (Mathematica script and package files)
EXTENSIONS = -name "*.m" -o -name "*.wl"
# Current git branch
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
.PHONY: all export-all $(PACKAGES)
# Default target: export sources for all detected packages
all: export-all
# Target to export all packages in one command
export-all: $(PACKAGES)
$(PACKAGES):
@echo "Exporting source for package: $@"
@VER=$$(cat $@/version.txt); \
find $@ -type f \( $(EXTENSIONS) \) | sort | while read -r file; do \
echo "=== FILENAME: $${file} ==="; \
cat "$$file"; \
printf "\n\n"; \
done > "$@_v$${VER}_Source.txt"; \
echo "$@_v$${VER}_Source.txt generado con éxito."
###############################################################################
# VERSIONING SECTION #
###############################################################################
# Detectar el Sistema Operativo para compatibilidad de 'sed'
UNAME_S := $(shell uname -s)
# Obtener el nombre del paquete actual (ej. QMB o QuantumWalks)
CURRENT_PKG := $(shell basename $(CURDIR))
.PHONY: bump
bump:
ifndef type
$(error You must specify a type. Example: make bump type=patch)
endif
@if [ "$(BRANCH)" != "develop" ]; then \
echo "Error: Version bumping must be performed on the 'develop' branch."; \
exit 1; \
fi
@CurrentVersion=$$(cat version.txt); \
Major=$$(echo $$CurrentVersion | cut -d. -f1); \
Minor=$$(echo $$CurrentVersion | cut -d. -f2); \
Patch=$$(echo $$CurrentVersion | cut -d. -f3); \
if [ "$(type)" = "major" ]; then \
Major=$$((Major + 1)); Minor=0; Patch=0; \
elif [ "$(type)" = "minor" ]; then \
Minor=$$((Minor + 1)); Patch=0; \
elif [ "$(type)" = "patch" ]; then \
Patch=$$((Patch + 1)); \
else \
echo "Error: Define type as 'major', 'minor', or 'patch'"; \
exit 1; \
fi; \
NewVersion="$$Major.$$Minor.$$Patch"; \
echo $$NewVersion > version.txt; \
echo "Updating files to v$$NewVersion..."; \
if [ "$(UNAME_S)" = "Darwin" ]; then \
sed -i '' "s/^\([ \t]*\)Version -> \"[^\"]*\"/\1Version -> \"$$NewVersion\"/" PacletInfo.wl; \
sed -i '' "s/\(\*\*Current Version\*\*:\) v[0-9.]*/\1 v$$NewVersion/" README.md; \
sed -i '' "s/\(\*\*$(CURRENT_PKG)\*\*:\) v[0-9.]*/\1 v$$NewVersion/" ../README.md; \
else \
sed -i "s/^\([ \t]*\)Version -> \"[^\"]*\"/\1Version -> \"$$NewVersion\"/" PacletInfo.wl; \
sed -i "s/\(\*\*Current Version\*\*:\) v[0-9.]*/\1 v$$NewVersion/" README.md; \
sed -i "s/\(\*\*$(CURRENT_PKG)\*\*:\) v[0-9.]*/\1 v$$NewVersion/" ../README.md; \
fi; \
git add version.txt PacletInfo.wl README.md ../README.md; \
git commit -m "Bump $(CURRENT_PKG) version to $$NewVersion"; \
echo "Successfully bumped $(type) version. New version: $$NewVersion"; \
$(MAKE) release
###############################################################################
# GIT RELEASE SECTION #
###############################################################################
PKG_NAME ?= $(shell basename $(CURDIR))
.PHONY: release
release:
@if [ "$(PKG_NAME)" != "QMB" ] && [ "$(PKG_NAME)" != "QuantumWalks" ]; then \
echo "Error: Release can only be run from the QMB or QuantumWalks directories."; \
exit 1; \
fi; \
if [ "$(BRANCH)" != "develop" ]; then \
echo "Error: The release process must start from the 'develop' branch."; \
exit 1; \
fi; \
CurrentVersion=$$(cat version.txt); \
echo "Starting release process for $(PKG_NAME) v$$CurrentVersion..."; \
git checkout main || { echo "Error: Failed to checkout main."; exit 1; }; \
git merge develop -m "Merge develop into main for release $(PKG_NAME)-v$$CurrentVersion" || { echo "Error: Merge failed."; exit 1; }; \
git tag -a "$(PKG_NAME)-v$$CurrentVersion" -m "Release $(PKG_NAME)-v$$CurrentVersion"; \
echo "Pushing to remote..."; \
sleep 1; \
git push origin main --tags || { echo "Retrying push..."; sleep 2; git push origin main --tags; } || { echo "Error: Push failed."; exit 1; }; \
echo "Synchronizing develop with main..."; \
git checkout develop; \
git merge main -m "Sync develop with main after release $(PKG_NAME)-v$$CurrentVersion"; \
git push origin develop; \
echo "Release $(PKG_NAME)-v$$CurrentVersion successfully merged, tagged, and synchronized."
###############################################################################
# CLEAN SECTION #
###############################################################################
.PHONY: clean
clean:
@echo "Cleaning up exported source files..."
@rm -f *_v*_Source.txt
@echo "Cleanup complete."
###############################################################################
# GOOGLE DRIVE UPLOAD SECTION #
###############################################################################
DriveRemote := gdrive
DrivePath := WolframSources
.PHONY: upload
# ---------------------------------------------------------------------------
# upload:
# Diseñado para ejecutarse DESDE LA RAÍZ del proyecto.
# ---------------------------------------------------------------------------
upload:
ifndef pkg
$(error Error: Debes especificar el paquete. Ejemplo: make upload pkg=QMB)
endif
@VER=$$(cat $(pkg)/version.txt); \
Filename="$(pkg)_v$${VER}_Source.txt"; \
if [ ! -f "$$Filename" ]; then \
echo "Archivo $$Filename no encontrado. Generándolo..."; \
$(MAKE) $(pkg); \
fi; \
echo "Subiendo $$Filename a Google Drive ($(DrivePath))..."; \
rclone copy "$$Filename" $(DriveRemote):$(DrivePath) --progress && \
echo "Carga de $$Filename completada con éxito."