From 03d5a3b28b4f306913af7f690dbb05989e7ab3b5 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sun, 22 Sep 2019 06:55:05 +0100 Subject: [PATCH 1/2] feat: allow pushing directly to upstream remote BREAKING CHANGE: Multiple arguments have been added to the `commit_push` shell script. This includes logically reordering the arguments. BREAKING CHANGE: The pillar structure has been modified according to the changes made. --- pillar.example | 32 ++++++++++++++------- ssf/config/formulas.sls | 13 +++++++-- ssf/defaults.yaml | 22 ++++++++++---- ssf/files/default/git/git_20_commit_push.sh | 29 ++++++++++++++----- ssf/formulas.yaml | 3 ++ 5 files changed, 73 insertions(+), 26 deletions(-) diff --git a/pillar.example b/pillar.example index ad063f53..257cbb08 100644 --- a/pillar.example +++ b/pillar.example @@ -18,24 +18,24 @@ ssf: ### Your GitHub configuration github: user: your_github_username - ### Remote to `git push` to - ### Default shown below will be used if left commented out - # push_remote: origin ### Local file to capture the GitHub API response when automatically ### creating the PR, prevents spamming the Salt output; ### Default shown below will be used if left commented out # file_api_response: github_api_response ### All `git`-related states default to `False`; enable here as required ### When testing this formula, the layout below is recommended: - ### - Branch is prepared and changes are added/removed - ### - Commit, push and PR creation are not performed + ### - Branch is prepared, changes are added/removed and a commit is prepared + ### - The commit isn't pushed, neither directly nor via. a newly created PR states: prepare: active: true add_rm: active: true - # commit_push: - # active: true + commit_push: + active: true + # push: + # active: true + # via_PR: false create_PR: # active: true ### This is a necessary override since the default script does not @@ -43,15 +43,27 @@ ssf: ### and simply add your personal token at the top of the script source: salt://ssf/files/your_directory/git/git_30_create_PR.sh - ### Any customisations to the formulas can be made here, e.g. for testing purposes + ### Any customisations to the formulas can be made here ### Usually, this is unnecessary but a likely override could be an upstream tracking - ### branch that doesn't match the value set above, i.e. `ssf:git:branch:upstream`. + ### branch that doesn't match the default values semrel_formulas: ssf: context: git: + # Override the names of the local tracking branches to use branch: - upstream: master + upstream: my_upstream_tracking_branch + github: + # Override the configuration of the remotes + remote: + # The upstream formula repo + upstream: + name: upstream + branch: master + # Your fork of the repo + fork: + name: origin + branch: master ### No formulas or files are active by default ### State the formulas and files to work through when running the formula diff --git a/ssf/config/formulas.sls b/ssf/config/formulas.sls index 1a8427c9..f78bd5f3 100644 --- a/ssf/config/formulas.sls +++ b/ssf/config/formulas.sls @@ -27,7 +27,7 @@ prepare-git-branch-for-{{ formula }}: - cwd: {{ ssf.formulas_path }}/{{ formula }}/ - args: >- prepare-git-branch-for-{{ formula }} - {{ context.git.branch.upstream | d(ssf.git.branch.upstream) }} + {{ context.git.branch.upstream }} {{ context.git.branch.pr }} {{ context.git.commit.body | regex_escape }} - runas: {{ ssf.user }} @@ -138,25 +138,32 @@ prepare-git-branch-for-{{ formula }}: {#- Stage 3: Run the script (`git` commands) to commit and push the branch #} {%- if ssf.git.states.commit_push.active %} +{%- set push_opts = ssf.git.states.commit_push.push %} commit-and-push-{{ formula }}: cmd.script: - source: {{ ssf.git.states.commit_push.source }} - cwd: {{ ssf.formulas_path }}/{{ formula }}/ - args: >- commit-and-push-{{ formula }} + {{ context.git.branch.upstream }} {{ context.git.branch.pr }} {{ context.git.commit.body | regex_escape }} {{ context.git.commit.title | regex_escape }} {{ context.git.commit.body | regex_escape }} {{ ssf.git.commit.options | regex_escape }} - {{ ssf.git.github.push_remote }} + {{ push_opts.active }} + {{ push_opts.via_PR }} + {{ context.git.github.remote.fork.name }} + {{ context.git.github.remote.fork.branch }} + {{ context.git.github.remote.upstream.name }} + {{ context.git.github.remote.upstream.branch }} - runas: {{ ssf.user }} - stateful: True {%- endif %} {#- Stage 4: Run the script (`curl` commands) to use the GitHub API to create the PR, if an existing PR isn't found #} -{%- if ssf.git.states.create_PR.active %} +{%- if ssf.git.states.create_PR.active and push_opts.active and push_opts.via_PR %} create-github-PR-for-{{ formula }}: cmd.script: - source: {{ ssf.git.states.create_PR.source }} diff --git a/ssf/defaults.yaml b/ssf/defaults.yaml index 0dcd9671..f29f905a 100644 --- a/ssf/defaults.yaml +++ b/ssf/defaults.yaml @@ -7,20 +7,29 @@ ssf_node_anchors: context: &context_default git: branch: + # TODO: `base` can be removed in favour of `github:remote:upstream:branch` base: master - pr: chore/standardise-structure + pr: chore/local-use-only-to-push-to-main-branch + upstream: upstream commit: # NOTE: The version number in the `body` is automatically updated during the # release phase via. `pre-commit_semantic-release.sh` # An alternative method could be to use: # `git describe --abbrev=0 --tags` # yamllint disable rule:line-length - title: 'fix(repo): provide EPEL repo configuration for `Amazon Linux-2`' - body: '* Semi-automated using https://github.com/myii/ssf-formula/pull/38' + title: 'ci(kitchen): change `log_level` to `debug` instead of `info`' + body: '* Automated using https://github.com/myii/ssf-formula/pull/41' # yamllint enable rule:line-length github: owner: saltstack-formulas repo: '' + remote: + upstream: + name: upstream + branch: master + fork: + name: origin + branch: master inspec_suites_kitchen: &isk_default 0: &isk_suite_default name: default @@ -168,13 +177,10 @@ ssf: semrel_formulas: [] semrel_files: [] git: - branch: - upstream: upstream commit: options: '' github: user: '' - push_remote: origin file_api_response: github_api_response states: prepare: @@ -186,6 +192,10 @@ ssf: commit_push: active: false source: salt://ssf/files/default/git/git_20_commit_push.sh + push: + active: false + # Push commit via. PR; if not, push directly to the repo's main branch + via_PR: true create_PR: active: false source: salt://ssf/files/default/git/git_30_create_PR.sh diff --git a/ssf/files/default/git/git_20_commit_push.sh b/ssf/files/default/git/git_20_commit_push.sh index d5cd42fe..a6e5bef7 100755 --- a/ssf/files/default/git/git_20_commit_push.sh +++ b/ssf/files/default/git/git_20_commit_push.sh @@ -4,12 +4,18 @@ # Collect incoming arguments STATE=${1} -BRANCH_PR=${2} -COMMIT_GREP=${3} -COMMIT_TITLE=${4} -COMMIT_BODY=${5} -COMMIT_OPTIONS=${6} -PUSH_TO_REMOTE=${7} +BRANCH_UPSTREAM=${2} +BRANCH_PR=${3} +COMMIT_GREP=${4} +COMMIT_TITLE=${5} +COMMIT_BODY=${6} +COMMIT_OPTIONS=${7} +PUSH_ACTIVE=${8} +PUSH_VIA_PR=${9} +REMOTE_FORK_NAME=${10} +REMOTE_FORK_BRANCH=${11} +REMOTE_UPSTREAM_NAME=${12} +REMOTE_UPSTREAM_BRANCH=${13} # Prepare initial state line variables CHANGED=True COMMENT='Command `'${STATE}'` run' @@ -26,7 +32,16 @@ fi # Perform actions git commit ${AMEND} "${COMMIT_OPTIONS}" -m "${COMMIT_TITLE}" -m "${COMMIT_BODY}" -git push ${FORCE} -u ${PUSH_TO_REMOTE} ${BRANCH_PR} +if [ "${PUSH_ACTIVE}" = "True" ]; then + if [ "${PUSH_VIA_PR}" = "True" ]; then + git push ${FORCE} -u ${REMOTE_FORK_NAME} ${BRANCH_PR} + else + git checkout ${BRANCH_UPSTREAM} + git merge ${BRANCH_PR} + git push ${REMOTE_UPSTREAM_NAME} HEAD:${REMOTE_UPSTREAM_BRANCH} + git branch -d ${BRANCH_PR} + fi +fi # Write the state line echo "changed=${CHANGED} comment='${COMMENT}'" diff --git a/ssf/formulas.yaml b/ssf/formulas.yaml index db7e733f..f0f117b3 100644 --- a/ssf/formulas.yaml +++ b/ssf/formulas.yaml @@ -1361,6 +1361,9 @@ ssf: branch: base: develop github: + remote: + upstream: + branch: develop repo: template-formula inspec_suites_kitchen: 0: From be06bd80e002286aacbd2623e3ab562fdce79d70 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 23 Sep 2019 17:21:22 +0100 Subject: [PATCH 2/2] feat(kitchen): change `log_level` to `debug` instead of `info` --- ssf/files/default/kitchen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssf/files/default/kitchen.yml b/ssf/files/default/kitchen.yml index c8913ef3..33f77ea7 100644 --- a/ssf/files/default/kitchen.yml +++ b/ssf/files/default/kitchen.yml @@ -146,7 +146,7 @@ platforms: provisioner: name: salt_solo - log_level: info + log_level: debug salt_install: none require_chef: false formula: {{ semrel_formula }}