Skip to content

Commit

Permalink
Release automation update (#103)
Browse files Browse the repository at this point in the history
* Add call to the new github action for setting chart version (my fork currently)

* switch to my github actions branch

* use issue title instead of name param

* Squash of the commits for v2 of the release automation (original commit messages were... not good)

* Remove unnecessary definitions

* Fix release_body typo
  • Loading branch information
jacobsee authored Jul 31, 2020
1 parent f6b9b1e commit 94c9333
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 30 deletions.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Creating a LodeStar Release
about: A template to use for releasing
title: v1.0.0
labels: ''
assignees: ''

---

This repository contains GitHub workflows for managing releases automatically.

**Please name this issue what you would like the new release to be called. E.x. "v1.0.0"**

The following slash commands are available to use in comments on this issue:

| Command | Description | Parameters |
|---|---|---|
| `/release` | Creates a new released based on the current state of the `master` branch | `frontend=<version>`<br/>`backend=<version>`<br/>`gitapi=<version>`<br/>`dispatcher=<version>`<br/>`agnosticv=<version>`<br/>`anarchy=<version>`<br/>`poolboy=<version>` |
| `/promote` | Promotes the created release to the next environment | N/A |
| `/cancel` | Cancels the current release (closes this issue) | N/A |
19 changes: 19 additions & 0 deletions .github/workflows/cancel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Cancel Dispatch

on:
repository_dispatch:
types: [cancel-command]
jobs:
promote-release:
runs-on: ubuntu-latest
steps:
- name: Set Env Variables
id: env_info
run: |
echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH)
echo ::set-output name=requestor::$(jq .client_payload.github.actor $GITHUB_EVENT_PATH)
- name: Close Issue
uses: peter-evans/close-issue@v1
with:
issue-number: ${{ steps.env_info.outputs.issuenm }}
comment: Cancelling rollout as requested by ${{ steps.env_info.outputs.requestor }}.
2 changes: 1 addition & 1 deletion .github/workflows/chat-ops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
uses: peter-evans/slash-command-dispatch@v1
with:
token: ${{ secrets.ACTIONS_TOKEN }}
commands: release, release-rc, promote
commands: release, release-rc, promote, cancel
named-args: true
44 changes: 36 additions & 8 deletions .github/workflows/promote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@ on:
types: [promote-command]
jobs:
promote-release:
if: ${{ github.event.client_payload.slash_command.env }} && ${{ github.event.client_payload.slash_command.name }}
runs-on: ubuntu-latest
steps:
- name: Set Env Variables
id: env_info
run: |
echo ::set-output name=issuetitle::$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH)
echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH)
echo ::set-output name=labels::$(jq .client_payload.github.payload.issue.labels $GITHUB_EVENT_PATH)
echo ::set-output name=requestor::$(jq .client_payload.github.actor $GITHUB_EVENT_PATH)
- name: Set New Env (Integration)
if: ${{ !contains(steps.env_info.outputs.labels, 'promoted to integration') }}
run: |
echo ::set-env name=NEW_ENV::integration
- name: Set New Env (Production)
if: ${{ contains(steps.env_info.outputs.labels, 'promoted to integration') }}
run: |
echo ::set-env name=NEW_ENV::production
- uses: actions/checkout@v2
with:
ref: ${{ github.event.client_payload.slash_command.name }}
ref: ${{ steps.env_info.outputs.issuetitle }}
- name: GitHub Pull Request Action
id: create_pr
uses: repo-sync/[email protected]
with:
source_branch: ${{ github.event.client_payload.slash_command.name }}
destination_branch: ${{ github.event.client_payload.slash_command.env }}
source_branch: ${{ steps.env_info.outputs.issuetitle }}
destination_branch: ${{ env.NEW_ENV }}
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_title: "Promoting ${{ github.event.client_payload.slash_command.name }} to ${{ github.event.client_payload.slash_command.env }}"
pr_body: "Promoting release ${{ github.event.client_payload.slash_command.name }} to the ${{ github.event.client_payload.slash_command.env }} environment as requested by @${{ steps.env_info.outputs.requestor }}."
pr_title: "Promoting ${{ steps.env_info.outputs.issuetitle }} to ${{ env.NEW_ENV }}"
pr_body: "Promoting release ${{ steps.env_info.outputs.issuetitle }} to the $NEW_ENV environment as requested by @${{ steps.env_info.outputs.requestor }}."
- name: Get PR number
id: pr_num
run: |
Expand All @@ -38,7 +48,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{steps.pr_num.outputs.prnm}},
labels: ["${{github.event.client_payload.slash_command.name }}"]
labels: ["${{ steps.env_info.outputs.issuetitle }}"]
})
- name: Auto-merge
uses: actions/github-script@v2
Expand All @@ -51,4 +61,22 @@ jobs:
pull_number: ${{ steps.pr_num.outputs.prnm}},
merge_method: "squash"
})
- name: Apply label to issue
uses: actions/github-script@v1
if: ${{ steps.create_label.outcome == 'success' }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{steps.env_info.outputs.issuenm}},
labels: ["promoted to ${{ env.NEW_ENV }}"]
})
- name: Create comment
uses: peter-evans/create-or-update-comment@v1
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
issue-number: "${{ steps.env_info.outputs.issuenm }}"
body: |
Promoted release ${{ steps.env_info.outputs.issuetitle }} to ${{ env.NEW_ENV }}!
51 changes: 39 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ on:
types: [release-command]
jobs:
create-release-branch:
if: ${{ github.event.client_payload.slash_command.name }}
runs-on: ubuntu-latest
steps:
- name: Get Environment Info
id: env_info
run: |
echo ::set-output name=release::$(git ls-remote --heads https://github.com/$GITHUB_REPOSITORY ${{ github.event.client_payload.slash_command.name }})
ISSUE_TITLE=$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH)
echo ::set-output name=release::$(git ls-remote --heads https://github.com/$GITHUB_REPOSITORY $ISSUE_TITLE)
echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH)
echo ::set-output name=issuetitle::$ISSUE_TITLE
- name: Create release branch
uses: peterjgrainger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: ${{ github.event.client_payload.slash_command.name }}
branch: "${{ steps.env_info.outputs.issuetitle }}"
if: ${{ steps.env_info.outputs.release == null }}
- name: Alert that release already exists
run: |
echo "Release branch ${{ github.event.client_payload.slash_command.name }} already exists. Skipping..."
echo "Release branch ${{ steps.env_info.outputs.issuetitle }} already exists. Skipping..."
if: ${{ steps.env_info.outputs.release != null }}
- name: Check if label exists
uses: actions/github-script@v1
Expand All @@ -34,7 +35,7 @@ jobs:
github.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: "${{ github.event.client_payload.slash_command.name }}"
name: "${{ steps.env_info.outputs.issuetitle }}"
})
- name: Create label to be used for release
uses: actions/github-script@v1
Expand All @@ -45,7 +46,7 @@ jobs:
github.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: "${{ github.event.client_payload.slash_command.name }}",
name: "${{ steps.env_info.outputs.issuetitle }}",
color: "2d5893"
})
if: ${{ steps.label_check.outcome == 'failure' }}
Expand All @@ -59,7 +60,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{steps.env_info.outputs.issuenm}},
labels: ["${{github.event.client_payload.slash_command.name }}"]
labels: ["${{ steps.env_info.outputs.issuetitle }}"]
})
update-release-pointers:
Expand All @@ -69,10 +70,12 @@ jobs:
- name: Get Environment Info
id: env_info
run: |
echo ::set-output name=issuetitle::$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH)
echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH)
echo ::set-output name=comment_url::$(jq .client_payload.github.payload.comment.html_url $GITHUB_EVENT_PATH)
- uses: actions/checkout@v2
with:
ref: ${{ github.event.client_payload.slash_command.name }}
ref: ${{ steps.env_info.outputs.issuetitle }}
- name: Update Frontend Release
if: ${{ github.event.client_payload.slash_command.frontend != null }}
uses: mikefarah/[email protected]
Expand Down Expand Up @@ -112,11 +115,35 @@ jobs:
uses: redhat-cop/github-actions/set-helm-version@master
with:
path: applications
chart_version: ${{ github.event.client_payload.slash_command.name }}
app_version: ${{ github.event.client_payload.slash_command.name }}
chart_version: "${{ steps.env_info.outputs.issuetitle }}"
app_version: "${{ steps.env_info.outputs.issuetitle }}"
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: ${{ github.event.client_payload.slash_command.name }}
branch: "${{ steps.env_info.outputs.issuetitle }}"
commit_message: "Merging changes requested from ${{ steps.env_info.outputs.comment_url }}"

- name: 'Get Previous tag'
id: previoustag
uses: actions-ecosystem/action-get-latest-tag@v1
- name: Generate Release Body
id: release_body
run: |
echo ::set-output name=text::$(git log ${{ steps.previoustag.outputs.tag }}..HEAD --pretty=format:"- %h %s by %an" --no-merges)
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.env_info.outputs.issuetitle }}
release_name: ${{ steps.env_info.outputs.issuetitle }}
body: ${{ steps.release_body.outputs.text }}
draft: false
prerelease: false
- name: Create comment
uses: peter-evans/create-or-update-comment@v1
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
issue-number: "${{ steps.env_info.outputs.issuenm }}"
body: |
Created release ${{ steps.env_info.outputs.issuetitle }}!
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ Automatic syncing, pruning, and self healing is enabled for this project - so co

## Releases

Creating releases is automated through the use of GitHub Actions Workflows. To create a release, you can just create an issue in this repository and use the below triggers in an issue comment to begin:
Creating releases is automated through the use of GitHub Actions Workflows. To create a release, you can just create an issue in this repository named as the release you'd like to create using the "Creating a release" template, and use the below triggers in an issue comment to begin:

`/release` - This trigger along with the appropriate parameters can be used to create a release branch that will then be used to promote the appropriate changes into a new environment branch. This can be run multiple times while adjusting various version that you will be using with a release.The following parameters can be passed to it:
`/release` - This trigger along with the appropriate parameters can be used to create a release branch that will then be used to promote the appropriate changes into a new environment branch. The following parameters can be passed to it:

| Variable | Description | Required |
|:---------|:------------|:---------|
|name|Name of the release. This will be used for naming the release branch and label for a release.|yes|
|frontend|The version to use for the frontend application|no|
|backend|The version to use for the backend application|no|
|gitapi|The version to use for the Git API|no|
Expand All @@ -49,10 +48,6 @@ Creating releases is automated through the use of GitHub Actions Workflows. To c
|anarchy|The version to use for Anarchy|no|
|poolboy|The version to use for Poolboy|no|

`/promote` - This trigger along with the appropriate parameters can be used to promote the changes contained in a release branch into a specified environment branch that ArgoCD is watching. These promotions are auto-merged, so you should be sure that you are ready for a promotion when you run this command. It accepts that following parameters:

| Variable | Description | Required |
|:---------|:------------|:---------|
|name|Name of the release.|yes|
|env|The name of the environment branch that you wish to merge your changes into|yes|
`/promote` - This trigger along with the appropriate parameters can be used to promote the changes contained in a release branch into a specified environment branch that ArgoCD is watching. These promotions are auto-merged, so you should be sure that you are ready for a promotion when you run this command. It does not accept any parameters.

`/cancel` - This trigger cancels the rollout/closes the release issue and signals that a new issue should be created if a release is still desired.

0 comments on commit 94c9333

Please sign in to comment.