Skip to content

Commit

Permalink
Merge pull request #201 from Knowledge-Graph-Hub/make-release
Browse files Browse the repository at this point in the history
Pre-release and release using Makefile
  • Loading branch information
hrshdhgd authored Jul 30, 2024
2 parents 9abb955 + ef008ed commit d533d1c
Show file tree
Hide file tree
Showing 6 changed files with 558 additions and 408 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Release

on:
push:
tags:
- "v*.*.*"
# push:
# tags:
# - "v*.*.*"
workflow_dispatch:

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,5 @@ data/transformed/uniprot_genome_features/*.tsv
kg_microbe/transform_utils/uniprot/tmp/relevant_file_content.txt
kg_microbe/transform_utils/uniprot/tmp/nodes_and_edges/*
data/transformed/uniprot_genome_features/uniprot_kgx.zip
data_merged.**
*.tar.gz
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ feba-schema-diagram:
--output-file notebooks/schema.pdf


include kg-microbe.Makefile
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
## Merge
- `poetry run kg merge`: This merges all transformed graphs above.

## Release
### Requirements
In order to be able to make KG releases on this repository, you'll need:
- Appropriate permissions to this repository.
- A Github token that has permissions on this repository. [This is how you set it in GitHub](https://docs.github.com/en/organizations/managing-programmatic-access-to-your-organization/setting-a-personal-access-token-policy-for-your-organization#restricting-access-by-personal-access-tokens-classic). Make sure your token has access to this project.
- Save this token locally assigned to the environemnt variable `GH_TOKEN`
```shell
export GH_TOKEN = XXXX
```
or add it to your `~/.bash_profile` or `~/.bashrc` file.



# Contributors
Please remember to run `poetry run tox` before every commit to make sure the code you commit is error-free.

Expand Down
99 changes: 99 additions & 0 deletions kg-microbe.Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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)

.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; \
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); \
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 -f%z "$(TARFILE)") -gt 2147483648 ]; then \
echo "$(TARFILE) is larger than 2GB. Splitting..."; \
split -b $(PART_SIZE) -d -a 3 $(TARFILE) $(TARFILE).part-; \
for part in $(TARFILE).part-*; do \
mv $$part $${part}.tar.gz; \
done; \
rm -f $(TARFILE); \
echo "$(TARFILE) split into smaller parts successfully."; \
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; \
for part in *.part-*.tar.gz; do \
gh release upload $$TAG_NAME $$part --repo $(REPO_OWNER)/$(REPO_NAME); \
done; \
rm -f *.tar.gz *.part-*.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; \
for part in *.part-*.tar.gz; do \
gh release upload $$TAG $$part --repo $(REPO_OWNER)/$(REPO_NAME); \
done; \
rm -f *.tar.gz *.part-*.tar.gz; \
echo "Release $$TAG created successfully."
endef

capitalize = $(subst $(1),$(shell echo $(1) | tr '[:lower:]' '[:upper:]'),$(1))
Loading

0 comments on commit d533d1c

Please sign in to comment.