mirror of
https://github.com/MarlinFirmware/Configurations.git
synced 2025-07-11 08:47:54 -06:00
✅ Fix deploy script
This commit is contained in:
parent
a261846306
commit
17c4846dda
2 changed files with 36 additions and 25 deletions
17
.github/workflows/deploy.yml
vendored
17
.github/workflows/deploy.yml
vendored
|
@ -21,7 +21,20 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Check out
|
- name: Check out
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Fetch all history for all branches and tags
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }} # Use the built-in token for authentication
|
||||||
|
|
||||||
# Run the mfconfig script with CI action
|
- name: Fetch all branches
|
||||||
- name: Deploy bugfix-2.1.x
|
run: git fetch --all
|
||||||
|
|
||||||
|
- name: Set up Git identity
|
||||||
|
run: |
|
||||||
|
git config --global user.email "github-actions@github.com"
|
||||||
|
git config --global user.name "GitHub Actions"
|
||||||
|
|
||||||
|
- name: Build bugfix-2.1.x
|
||||||
run: bin/mfconfig CI
|
run: bin/mfconfig CI
|
||||||
|
|
||||||
|
- name: Push bugfix-2.1.x
|
||||||
|
run: git push -f origin WORK:bugfix-2.1.x
|
||||||
|
|
44
bin/mfconfig
44
bin/mfconfig
|
@ -38,7 +38,7 @@ IMPORT = sys.argv[2] if len(sys.argv) > 2 else 'import-2.1.x'
|
||||||
EXPORT = sys.argv[3] if len(sys.argv) > 3 else 'bugfix-2.1.x'
|
EXPORT = sys.argv[3] if len(sys.argv) > 3 else 'bugfix-2.1.x'
|
||||||
|
|
||||||
# Get repo paths
|
# Get repo paths
|
||||||
CI = False
|
CI = os.environ.get('GITHUB_ACTIONS') == 'true'
|
||||||
if ACTION == 'CI':
|
if ACTION == 'CI':
|
||||||
_REPOS = "."
|
_REPOS = "."
|
||||||
REPOS = Path(_REPOS)
|
REPOS = Path(_REPOS)
|
||||||
|
@ -68,20 +68,23 @@ if not CONFIGREPO.exists():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Run git within CONFIGREPO
|
# Run git within CONFIGREPO
|
||||||
GITSTDERR = None if DEBUG else subprocess.DEVNULL
|
GITSTDERR = subprocess.PIPE if DEBUG else subprocess.DEVNULL
|
||||||
def git(etc):
|
def git(etc):
|
||||||
if DEBUG:
|
if DEBUG: print(f"> git {' '.join(etc)}")
|
||||||
print(f"> git {' '.join(etc)}")
|
|
||||||
if etc[0] == "push":
|
result = subprocess.run(["git"] + etc, cwd=CONFIGREPO, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||||
info("*** DRY RUN ***")
|
|
||||||
return subprocess.run(["echo"])
|
if result.returncode != 0:
|
||||||
return subprocess.run(["git"] + etc, cwd=CONFIGREPO, stdout=subprocess.PIPE, stderr=GITSTDERR)
|
print(f"Git command failed: git {' '.join(etc)}")
|
||||||
|
print(f"Error output: {result.stderr}")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
# Get the current branch name
|
# Get the current branch name
|
||||||
def branch(): return git(["rev-parse", "--abbrev-ref", "HEAD"])
|
def branch(): return git(["rev-parse", "--abbrev-ref", "HEAD"])
|
||||||
|
|
||||||
# git add . ; git commit -m ...
|
# git add . ; git commit -m ...
|
||||||
def commit(msg, who="."): git(["add", who]) ; return git(["commit", "-m", msg])
|
def commit(msg, who="."): git(["add", who]) ; return git(["commit", "-m", f'"{msg}"'])
|
||||||
|
|
||||||
# git checkout ...
|
# git checkout ...
|
||||||
def checkout(etc): return git(["checkout"] + ([etc] if isinstance(etc, str) else etc))
|
def checkout(etc): return git(["checkout"] + ([etc] if isinstance(etc, str) else etc))
|
||||||
|
@ -90,11 +93,7 @@ def checkout(etc): return git(["checkout"] + ([etc] if isinstance(etc, str) else
|
||||||
def gitbd(name): return git(["branch", "-D", name]).stdout
|
def gitbd(name): return git(["branch", "-D", name]).stdout
|
||||||
|
|
||||||
# git status --porcelain : to check for changes
|
# git status --porcelain : to check for changes
|
||||||
def changes(): return git(["status", "--porcelain"]).stdout.decode().strip()
|
def changes(): return git(["status", "--porcelain"]).stdout != ""
|
||||||
|
|
||||||
# Configure git user
|
|
||||||
git(["config", "user.email", "thinkyhead@users.noreply.github.com"])
|
|
||||||
git(["config", "user.name", "Scott Lahteine"])
|
|
||||||
|
|
||||||
# Stash uncommitted changes at the destination?
|
# Stash uncommitted changes at the destination?
|
||||||
if changes():
|
if changes():
|
||||||
|
@ -179,9 +178,9 @@ if ACTION == "init":
|
||||||
f.writelines(outlines)
|
f.writelines(outlines)
|
||||||
|
|
||||||
# Create a fresh 'WORK' as a copy of 'init-repo' (README, LICENSE, etc.)
|
# Create a fresh 'WORK' as a copy of 'init-repo' (README, LICENSE, etc.)
|
||||||
gitbd("WORK")
|
if not CI: gitbd("WORK")
|
||||||
if CI: git(["fetch", "origin", "init-repo"])
|
REMOTE = "origin" if CI else "upstream"
|
||||||
checkout(["init-repo", "-b", "WORK"])
|
checkout([f"{REMOTE}/init-repo", "-b", "WORK"])
|
||||||
|
|
||||||
# Copy default configurations into the repo
|
# Copy default configurations into the repo
|
||||||
info("Create configs in default state...")
|
info("Create configs in default state...")
|
||||||
|
@ -193,7 +192,7 @@ if ACTION == "init":
|
||||||
shutil.copy(TEMPCON / "default" / fn.name, CONFIGCON / relpath)
|
shutil.copy(TEMPCON / "default" / fn.name, CONFIGCON / relpath)
|
||||||
|
|
||||||
# DEBUG: Commit the reset for review
|
# DEBUG: Commit the reset for review
|
||||||
if DEBUG: commit("[DEBUG] Create defaults")
|
if DEBUG > 1: commit("[DEBUG] Create defaults")
|
||||||
|
|
||||||
def replace_in_file(fn, search, replace):
|
def replace_in_file(fn, search, replace):
|
||||||
with open(fn, 'r') as f: lines = f.read()
|
with open(fn, 'r') as f: lines = f.read()
|
||||||
|
@ -203,7 +202,7 @@ if ACTION == "init":
|
||||||
replace_in_file(CONFIGREPO / "README.md", "%VERSION%", EXPORT.replace("release-", ""))
|
replace_in_file(CONFIGREPO / "README.md", "%VERSION%", EXPORT.replace("release-", ""))
|
||||||
|
|
||||||
# Commit all changes up to now; amend if not debugging
|
# Commit all changes up to now; amend if not debugging
|
||||||
if DEBUG:
|
if DEBUG > 1:
|
||||||
commit("[DEBUG] Update README.md version", "README.md")
|
commit("[DEBUG] Update README.md version", "README.md")
|
||||||
else:
|
else:
|
||||||
git(["add", "."])
|
git(["add", "."])
|
||||||
|
@ -234,16 +233,15 @@ if ACTION == "init":
|
||||||
shutil.rmtree(TEMP)
|
shutil.rmtree(TEMP)
|
||||||
|
|
||||||
# Push to the remote (if desired)
|
# Push to the remote (if desired)
|
||||||
if CI:
|
PUSH_YES = 'N'
|
||||||
PUSH_YES = 'Y'
|
if not CI:
|
||||||
else:
|
|
||||||
print()
|
print()
|
||||||
PUSH_YES = input(f"Push to upstream/{EXPORT}? [y/N] ")
|
PUSH_YES = input(f"Push to upstream/{EXPORT}? [y/N] ")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
REMOTE = "origin" if CI else "upstream"
|
REMOTE = "origin" if CI else "upstream"
|
||||||
|
|
||||||
if PUSH_YES in ('Y','y'):
|
if PUSH_YES.upper() in ('Y','YES'):
|
||||||
info("Push to remote...")
|
info("Push to remote...")
|
||||||
git(["push", "-f", REMOTE, f"WORK:{EXPORT}"])
|
git(["push", "-f", REMOTE, f"WORK:{EXPORT}"])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue