|
| 1 | +// This file is part of vscode-vba. |
| 2 | +// Copyright (c) 2023-present Lukas Neubert |
| 3 | +// This Source Code is subject to the terms of the Mozilla Public License 2.0. |
| 4 | + |
| 5 | +package main |
| 6 | + |
| 7 | +import os |
| 8 | +import bait.util |
| 9 | + |
| 10 | +const GIT_USER := 'tiabeast-bot' |
| 11 | +const GIT_MAIL := ' [email protected]' |
| 12 | + |
| 13 | +const IS_CI := os.getenv('CI') == 'true' |
| 14 | + |
| 15 | +fun main() { |
| 16 | + // Count the number of errors by adding the os.system return values |
| 17 | + mut errors := 0 |
| 18 | + |
| 19 | + if IS_CI { |
| 20 | + println('Configuring git user...') |
| 21 | + errors += git_command('config --global user.name "${GIT_USER}"') |
| 22 | + errors += git_command('config --global user.email "${GIT_MAIL}"') |
| 23 | + } |
| 24 | + |
| 25 | + target_repo_dir := '/tmp/vscode-vba-json' |
| 26 | + if os.exists(target_repo_dir) { |
| 27 | + os.rmdir_all(target_repo_dir) |
| 28 | + } |
| 29 | + |
| 30 | + errors += git_command('clone --depth 1 https://github.com/serkonda7/vscode-vba-json ${target_repo_dir}') |
| 31 | + |
| 32 | + errors += os.system('npm run convert-yaml') |
| 33 | + os.cp('./out', '${target_repo_dir}/syntaxes') |
| 34 | + |
| 35 | + // Sanity check for a reasonable file size |
| 36 | + text := os.read_file(target_repo_dir + '/syntaxes/vba.tmGrammar.json') |
| 37 | + if text.length < 1000 { |
| 38 | + eprintln('grammar is too small. Something went wrong.') |
| 39 | + exit(1) |
| 40 | + } |
| 41 | + |
| 42 | + // Stage changes |
| 43 | + errors += git_command('-C ${target_repo_dir} add .') |
| 44 | + |
| 45 | + // Exit if there is nothing to commit |
| 46 | + has_changes := git_command('-C ${target_repo_dir} diff-index --quiet HEAD') |
| 47 | + if has_changes == 0 { |
| 48 | + println('No changes to commit.') |
| 49 | + exit(0) |
| 50 | + } |
| 51 | + |
| 52 | + // Create commit |
| 53 | + println('Creating commit...') |
| 54 | + os.chdir(target_repo_dir) |
| 55 | + commit_msg := 'update grammars' |
| 56 | + errors += git_command('commit -m "${commit_msg}"') |
| 57 | + |
| 58 | + // Safety rebase and push changes |
| 59 | + println('Pushing changes...') |
| 60 | + errors += git_command('pull --rebase') |
| 61 | + errors += git_command('push') |
| 62 | + |
| 63 | + // Exit with the number of errors |
| 64 | + exit(errors) |
| 65 | +} |
| 66 | + |
| 67 | +fun git_command(cmd string) i32 { |
| 68 | + esc_cmd := util.shell_escape(cmd) |
| 69 | + return os.system('git ${esc_cmd}') |
| 70 | +} |
0 commit comments