Skip to content

Commit

Permalink
Merge pull request #41 from myii/feat/use-log-level-debug-in-kitchen
Browse files Browse the repository at this point in the history
feat: allow pushing directly to upstream remote
  • Loading branch information
myii authored Sep 23, 2019
2 parents 83bd987 + be06bd8 commit 1a27daf
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 27 deletions.
32 changes: 22 additions & 10 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,52 @@ 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
### contain a GitHub API token; copy the file to `your_directory`
### 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
Expand Down
13 changes: 10 additions & 3 deletions ssf/config/formulas.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down
22 changes: 16 additions & 6 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
29 changes: 22 additions & 7 deletions ssf/files/default/git/git_20_commit_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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}'"
2 changes: 1 addition & 1 deletion ssf/files/default/kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ platforms:

provisioner:
name: salt_solo
log_level: info
log_level: debug
salt_install: none
require_chef: false
formula: {{ semrel_formula }}
Expand Down
3 changes: 3 additions & 0 deletions ssf/formulas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,9 @@ ssf:
branch:
base: develop
github:
remote:
upstream:
branch: develop
repo: template-formula
inspec_suites_kitchen:
0:
Expand Down

0 comments on commit 1a27daf

Please sign in to comment.