mirror of
https://github.com/frappe/frappe_docker.git
synced 2025-01-10 00:37:53 +00:00
Use python script to get latest tags in CI
This commit is contained in:
parent
85a534c09d
commit
89236d8ed6
43
.github/scripts/WIP_generate_pwd.py
vendored
Normal file
43
.github/scripts/WIP_generate_pwd.py
vendored
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from get_latest_tags import get_latest_tag, update_env
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_env():
|
||||||
|
version = "13"
|
||||||
|
frappe_tag = get_latest_tag("frappe", version)
|
||||||
|
erpnext_tag = get_latest_tag("erpnext", version)
|
||||||
|
shutil.copyfile("example.env", ".env")
|
||||||
|
update_env(".env", frappe_tag, erpnext_tag)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_compose_file():
|
||||||
|
output = subprocess.check_output(
|
||||||
|
(
|
||||||
|
"docker-compose",
|
||||||
|
"-f",
|
||||||
|
"compose.yaml",
|
||||||
|
"-f",
|
||||||
|
"overrides/compose.erpnext.yaml",
|
||||||
|
"--env-file",
|
||||||
|
".env",
|
||||||
|
"config",
|
||||||
|
),
|
||||||
|
encoding="UTF-8",
|
||||||
|
)
|
||||||
|
text = f'version: "3.9"\n\n{output}'
|
||||||
|
with open("pwd.yml", "a+") as f:
|
||||||
|
f.seek(0)
|
||||||
|
f.truncate()
|
||||||
|
f.write(text)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
prepare_env()
|
||||||
|
generate_compose_file()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
18
.github/scripts/get-latest-tags.sh
vendored
18
.github/scripts/get-latest-tags.sh
vendored
@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
set -x
|
|
||||||
|
|
||||||
get_tag() {
|
|
||||||
tags=$(git ls-remote --refs --tags --sort='v:refname' "https://github.com/$1" "v$2.*")
|
|
||||||
tag=$(echo "$tags" | tail -n1 | sed 's/.*\///')
|
|
||||||
echo "$tag"
|
|
||||||
}
|
|
||||||
|
|
||||||
FRAPPE_VERSION=$(get_tag frappe/frappe "$VERSION")
|
|
||||||
ERPNEXT_VERSION=$(get_tag frappe/erpnext "$VERSION")
|
|
||||||
|
|
||||||
cat <<EOL >>"$GITHUB_ENV"
|
|
||||||
FRAPPE_VERSION=$FRAPPE_VERSION
|
|
||||||
ERPNEXT_VERSION=$ERPNEXT_VERSION
|
|
||||||
EOL
|
|
74
.github/scripts/get_latest_tags.py
vendored
Normal file
74
.github/scripts/get_latest_tags.py
vendored
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
|
Repo = Literal["frappe", "erpnext"]
|
||||||
|
MajorVersion = Literal["12", "13", "develop"]
|
||||||
|
|
||||||
|
|
||||||
|
def get_latest_tag(repo: Repo, version: MajorVersion) -> str:
|
||||||
|
if version == "develop":
|
||||||
|
return "develop"
|
||||||
|
regex = rf"v{version}.*"
|
||||||
|
refs = subprocess.check_output(
|
||||||
|
(
|
||||||
|
"git",
|
||||||
|
"ls-remote",
|
||||||
|
"--refs",
|
||||||
|
"--tags",
|
||||||
|
"--sort=v:refname",
|
||||||
|
f"https://github.com/frappe/{repo}",
|
||||||
|
str(regex),
|
||||||
|
),
|
||||||
|
encoding="UTF-8",
|
||||||
|
).split()[1::2]
|
||||||
|
|
||||||
|
if not refs:
|
||||||
|
raise RuntimeError(f'No tags found for version "{regex}"')
|
||||||
|
ref = refs[-1]
|
||||||
|
matches: list[str] = re.findall(regex, ref)
|
||||||
|
if not matches:
|
||||||
|
raise RuntimeError(f'Can\'t parse tag from ref "{ref}"')
|
||||||
|
return matches[0]
|
||||||
|
|
||||||
|
|
||||||
|
def update_env(file_name: str, frappe_tag: str, erpnext_tag: str | None = None):
|
||||||
|
text = f"\nFRAPPE_VERSION={frappe_tag}"
|
||||||
|
if erpnext_tag:
|
||||||
|
text += f"\nERPNEXT_VERSION={erpnext_tag}"
|
||||||
|
|
||||||
|
with open(file_name, "a") as f:
|
||||||
|
f.write(text)
|
||||||
|
|
||||||
|
|
||||||
|
def _print_resp(frappe_tag: str, erpnext_tag: str | None = None):
|
||||||
|
print(json.dumps({"frappe": frappe_tag, "erpnext": erpnext_tag}))
|
||||||
|
|
||||||
|
|
||||||
|
def main(_args: list[str]) -> int:
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--repo", choices=["frappe", "erpnext"], required=True)
|
||||||
|
parser.add_argument("--version", choices=["12", "13", "develop"], required=True)
|
||||||
|
args = parser.parse_args(_args)
|
||||||
|
|
||||||
|
frappe_tag = get_latest_tag("frappe", args.version)
|
||||||
|
if args.repo == "erpnext":
|
||||||
|
erpnext_tag = get_latest_tag("erpnext", args.version)
|
||||||
|
else:
|
||||||
|
erpnext_tag = None
|
||||||
|
|
||||||
|
file_name = os.getenv("GITHUB_ENV")
|
||||||
|
if file_name:
|
||||||
|
update_env(file_name, frappe_tag, erpnext_tag)
|
||||||
|
_print_resp(frappe_tag, erpnext_tag)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main(sys.argv[1:]))
|
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@ -65,9 +65,7 @@ jobs:
|
|||||||
uses: ndeloof/install-compose-action@4a33bc31f327b8231c4f343f6fba704fedc0fa23
|
uses: ndeloof/install-compose-action@4a33bc31f327b8231c4f343f6fba704fedc0fa23
|
||||||
|
|
||||||
- name: Get latest versions
|
- name: Get latest versions
|
||||||
run: ./.github/scripts/get-latest-tags.sh
|
run: ./.github/scripts/get_latest_tags.py --repo erpnext --version ${{ matrix.version }}
|
||||||
env:
|
|
||||||
VERSION: ${{ matrix.version }}
|
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
uses: docker/bake-action@v1.6.0
|
uses: docker/bake-action@v1.6.0
|
||||||
|
1
TODO.md
1
TODO.md
@ -1,5 +1,4 @@
|
|||||||
- [ ] Docs
|
- [ ] Docs
|
||||||
- [ ] Test with helm chart
|
- [ ] Test with helm chart
|
||||||
- [ ] CI (also: build only published tag)
|
|
||||||
- [ ] Play With Docker generation
|
- [ ] Play With Docker generation
|
||||||
- [ ] Custom app compose and dockerfile examples
|
- [ ] Custom app compose and dockerfile examples
|
||||||
|
Loading…
Reference in New Issue
Block a user