Skip to content

Commit

Permalink
feat(formulas.sls): ensure temporary date-based branch is removed
Browse files Browse the repository at this point in the history
Up to now, there's been a slight issue with doing direct pushes to repos
when there are no changes to be pushed.  For example, we currently need
`libtofs.jinja` to be updated across formulas but not all of the
formulas have this file; when running across all formulas, this will
cause the temporary date-based branch to be created but then not
removed.  This commit is a quick fix for that, where the starting branch
is tracked and then checked out again at the end, before removing the
temporary branch (if it is still available).
  • Loading branch information
myii committed Jul 19, 2020
1 parent 2829628 commit 71c7038
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ssf/config/formulas.sls
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{#- Determine the TOFS override directory for the current formula #}
{#- Can't use `formula` directly because some formula names are used as top-level pillar/config keys, such as `users-formula` #}
{%- set formula_tofs_dir = 'tofs_' ~ formula %}
{%- set branch_current = salt['git.current_branch']('{0}/{1}'.format(ssf.formulas_path, formula)) %}
{%- set branch_pr = context.git.branch.pr %}
{%- if not ssf.git.states.commit_push.push.via_PR %}
{%- set branch_pr = salt['system.get_system_date_time']() | replace(' ', '')
Expand Down Expand Up @@ -164,6 +165,10 @@ prepare-git-branch-for-{{ formula }}:
- onchanges_in:
- cmd: commit-and-push-{{ formula }}
{%- endif %}
{%- if not ssf.git.states.commit_push.push.via_PR and ssf.git.states.prepare.active %}
- require_in:
- cmd: cleanup-date-based-branch-for-{{ formula }}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
Expand Down Expand Up @@ -200,6 +205,10 @@ commit-and-push-{{ formula }}:
- runas: {{ ssf.user }}
{%- endif %}
- stateful: True
{%- if not ssf.git.states.commit_push.push.via_PR and ssf.git.states.prepare.active %}
- require_in:
- cmd: cleanup-date-based-branch-for-{{ formula }}
{%- endif %}
{%- endif %}
Expand Down Expand Up @@ -227,6 +236,27 @@ create-github-PR-for-{{ formula }}:
- onchanges:
- cmd: commit-and-push-{{ formula }}
{%- endif %}
{%- if not ssf.git.states.commit_push.push.via_PR and ssf.git.states.prepare.active %}
- require_in:
- cmd: cleanup-date-based-branch-for-{{ formula }}
{%- endif %}
{%- endif %}
{#- Stage 5: Rarely required but clean up `branch_pr` if date-based and still available #}
{%- if not ssf.git.states.commit_push.push.via_PR and ssf.git.states.prepare.active %}
cleanup-date-based-branch-for-{{ formula }}:
{#- TODO: Convert to `cmd.script`? #}
cmd.run:
- name: |
git checkout {{ branch_current }}
if [ "$(git branch --list {{ branch_pr }})" ]; then
git branch -d {{ branch_pr }}
fi
- cwd: {{ ssf.formulas_path }}/{{ formula }}/
{%- if running_as_root %}
- runas: {{ ssf.user }}
{%- endif %}
{%- endif %}
{#- [End] for semrel_formula, semrel_formula_specs in ... #}
Expand Down

0 comments on commit 71c7038

Please sign in to comment.