Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a skeleton for release&promotion workflows #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/cancel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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: |
ISSUE_TITLE=$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH)
echo ::set-output name=issuetitle::$ISSUE_TITLE
echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH)
echo ::set-output name=requestor::$(jq -r .client_payload.github.actor $GITHUB_EVENT_PATH)
- name: Delete branch
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{ github.token }}
branches: ${{ steps.env_info.outputs.issuetitle }}
- 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 }}.
15 changes: 15 additions & 0 deletions .github/workflows/chat-ops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Chat Ops

on:
issue_comment:
types: [created]

jobs:
launcher:
runs-on: ubuntu-latest
steps:
- name: Command Dispatch
uses: peter-evans/slash-command-dispatch@v2
with:
token: ${{ secrets.ACTIONS_TOKEN }}
commands: release, release-rc, promote, cancel, finish
26 changes: 26 additions & 0 deletions .github/workflows/finish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Finish Dispatch

on:
repository_dispatch:
types: [finish-command]
jobs:
promote-release:
runs-on: ubuntu-latest
steps:
- name: Set Env Variables
id: env_info
run: |
ISSUE_TITLE=$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH)
echo ::set-output name=issuetitle::$ISSUE_TITLE
echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH)
echo ::set-output name=requestor::$(jq -r .client_payload.github.actor $GITHUB_EVENT_PATH)
- name: Delete branch
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{ github.token }}
branches: ${{ steps.env_info.outputs.issuetitle }}
- name: Close Issue
uses: peter-evans/close-issue@v1
with:
issue-number: ${{ steps.env_info.outputs.issuenm }}
comment: Rollout finished by @${{ steps.env_info.outputs.requestor }} - closing issue.
81 changes: 81 additions & 0 deletions .github/workflows/promote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Promote Dispatch

on:
repository_dispatch:
types: [promote-command]
jobs:
promote-release:
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 "NEW_ENV=integration" >> $GITHUB_ENV
- name: Set New Env (Production)
if: ${{ contains(steps.env_info.outputs.labels, 'promoted to integration') }}
run: |
echo "NEW_ENV=production" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
ref: ${{ steps.env_info.outputs.issuetitle }}
- name: GitHub Pull Request Action
id: create_pr
uses: repo-sync/[email protected]
with:
source_branch: ${{ steps.env_info.outputs.issuetitle }}
destination_branch: ${{ env.NEW_ENV }}
github_token: ${{ secrets.GITHUB_TOKEN }}
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: |
echo ::set-output name=prnm::$( echo ${{ steps.create_pr.outputs.pr_url }} | awk -F'/' '{print $NF}')
# - name: Auto-merge
# uses: actions/github-script@v2
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# github.pulls.merge({
# owner: context.repo.owner,
# repo: context.repo.repo,
# pull_number: ${{ steps.pr_num.outputs.prnm}},
# merge_method: "squash"
# })
- name: Apply label to issue
uses: actions/github-script@v1
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 }}!
# - name: Delete branch
# if: ${{ env.NEW_ENV == 'production' }}
# uses: dawidd6/action-delete-branch@v3
# with:
# github_token: ${{ github.token }}
# branches: ${{ steps.env_info.outputs.issuetitle }}
# - name: Close Issue
# if: ${{ env.NEW_ENV == 'production' }}
# uses: peter-evans/close-issue@v1
# with:
# issue-number: ${{ steps.env_info.outputs.issuenm }}
# comment: Rollout completed by ${{ steps.env_info.outputs.requestor }} - closing issue.
143 changes: 143 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Release Dispatch

on:
repository_dispatch:
types: [release-command]
jobs:
create-release-branch:
runs-on: ubuntu-latest
steps:
- name: Get Environment Info
id: env_info
run: |
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: "${{ steps.env_info.outputs.issuetitle }}"
if: ${{ steps.env_info.outputs.release == null }}

- name: Alert that release already exists
run: |
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
id: label_check
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: "${{ steps.env_info.outputs.issuetitle }}"
})

- name: Create label to be used for release
uses: actions/github-script@v1
id: create_label
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: "${{ steps.env_info.outputs.issuetitle }}",
color: "2d5893"
})
if: ${{ steps.label_check.outcome == 'failure' }}

- 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: ["${{ steps.env_info.outputs.issuetitle }}"]
})

update-release-pointers:
runs-on: ubuntu-latest
needs: create-release-branch
env:
URL: ${{ secrets.RELEASE_NOTIFICATON_URL }}

## String to match for ImageTag replacement where applicable
ImageTagMatchString: 'imageTag:.*'

## End-to-End (E2E) testing - match string and replacement string
e2eTestMatchString: 'enabled: true'
e2eDisableReplacementString: 'enabled: false'


## LodeStar Overall Version String - value obtained at runtime
Versions_LodeStarMatchString: 'lodestar:.*'


steps:
- name: Get Environment Info
id: env_info
run: |
ISSUE_TITLE=$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH)
echo ::set-output name=issuetitle::$ISSUE_TITLE
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)
echo ::set-output name=lodestarVersion::"lodestar: ${ISSUE_TITLE}"

- uses: actions/checkout@v2
with:
ref: ${{ steps.env_info.outputs.issuetitle }}

- name: Commit Release Changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
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: Fetch Previous Release Info
id: previous_release
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: rht-labs/lodestar-deployment

- name: Generate Release Body
id: release_body
run: |
echo ::set-output name=text::$(git log ${{ steps.previous_release.outputs.release }}..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 Release 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 }}!