Skip to content

Commit

Permalink
Add GitHub Action for automatic release
Browse files Browse the repository at this point in the history
  • Loading branch information
sutaakar committed Aug 22, 2023
1 parent 4816d9d commit ea8f527
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 2 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/tag-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# This workflow will release Distributed Workloads stack

name: Tag and Release
on:
workflow_dispatch:
inputs:
release-version:
description: 'Release version of Distributed Workloads stack (i.e. v0.0.0)'
required: true
operator-version:
description: 'Published version of operator image (i.e. v0.0.0)'
required: true
mcad-version:
description: 'Published version of multi-cluster-app-dispatcher (i.e. v0.0.0)'
required: true
codeflare-sdk-version:
description: 'Published version of CodeFlare-SDK (i.e. v0.0.0)'
required: true
instascale-version:
description: 'Published version of InstaScale (i.e. v0.0.0)'
required: true
kuberay-version:
description: 'Published version of KubeRay (i.e. v0.0.0)'
required: true

jobs:
push:
runs-on: ubuntu-latest

# Permission required to create a release
permissions:
contents: write
pull-requests: write

env:
PR_BRANCH_NAME: adjustments-release-${{ github.event.inputs.release-version }}

steps:
- uses: actions/checkout@v3

- name: Set Go
uses: actions/setup-go@v3
with:
go-version: v1.19

- name: Verify that release doesn't exist yet
shell: bash {0}
run: |
gh release view ${{ github.event.inputs.release-version }}
status=$?
if [[ $status -eq 0 ]]; then
echo "Release ${{ github.event.inputs.release-version }} already exists."
exit 1
fi
env:
GITHUB_TOKEN: ${{ github.TOKEN }}

- name: Adjust Compatibility Matrix in readme
run: |
sed -i -E "s/(.*CodeFlare Operator.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.operator-version }}\2/" README.md
sed -i -E "s/(.*Multi-Cluster App Dispatcher.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.mcad-version }}\2/" README.md
sed -i -E "s/(.*CodeFlare-SDK.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.codeflare-sdk-version }}\2/" README.md
sed -i -E "s/(.*InstaScale.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.instascale-version }}\2/" README.md
sed -i -E "s/(.*KubeRay.*)v[0-9]+\.[0-9]+\.[0-9]+(.*)/\1${{ github.event.inputs.kuberay-version }}\2/" README.md
- name: Adjust dependencies in the tests
run: |
go get github.com/project-codeflare/codeflare-operator@${{ github.event.inputs.operator-version }}
go mod tidy
working-directory: tests

- name: Adjust CodeFlare notebook ImageStream
run: |
sed -i -E "s|(.*name: )v[0-9]+\.[0-9]+\.[0-9]+|\1${{ github.event.inputs.codeflare-sdk-version }}|" codeflare-notebook-imagestream.yaml
sed -i -E "s|(.*name: quay.io/project-codeflare/notebook:)v[0-9]+\.[0-9]+\.[0-9]+|\1${{ github.event.inputs.codeflare-sdk-version }}|" codeflare-notebook-imagestream.yaml
working-directory: codeflare-stack/base

- name: Commit changes in the code back to repository
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update dependency versions for release ${{ github.event.inputs.release-version }}
file_pattern: 'README.md *.yaml tests/go.mod tests/go.sum'
create_branch: true
branch: ${{ env.PR_BRANCH_NAME }}

- name: Create a PR with code changes
run: |
GIT_BRANCH=${GITHUB_REF#refs/heads/}
gh pr create --base "$GIT_BRANCH" --fill --head "${{ env.PR_BRANCH_NAME }}" --label "lgtm" --label "approved"
env:
GITHUB_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }}

- name: Wait until PR with code changes is merged
run: |
timeout 7200 bash -c 'until [[ $(gh pr view '${{ env.PR_BRANCH_NAME }}' --json state --jq .state) == "MERGED" ]]; do sleep 5 && echo "$(gh pr view '${{ env.PR_BRANCH_NAME }}' --json state --jq .state)"; done'
env:
GITHUB_TOKEN: ${{ github.TOKEN }}

- name: Delete remote branch
run: |
git push origin --delete ${{ env.PR_BRANCH_NAME }}
- name: Creates a release in GitHub
run: |
gh release create ${{ github.event.inputs.release-version }} --target ${{ github.ref }} --generate-notes
# Edit notes to add there compatibility matrix
sed --null-data -E "s/(.*<\!-- Compatibility Matrix start -->)(.*)(<\!-- Compatibility Matrix end -->.*)/\2/" README.md > release-notes.md
echo "" >> release-notes.md
echo "Upstream release notes can be found at https://github.com/project-codeflare/codeflare-operator/releases/tag/${{ github.event.inputs.operator-version }}" >> release-notes.md
echo "" >> release-notes.md
echo "$(gh release view --json body --jq .body)" >> release-notes.md
gh release edit ${{ github.event.inputs.release-version }} --notes-file release-notes.md
rm release-notes.md
env:
GITHUB_TOKEN: ${{ github.TOKEN }}
shell: bash
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ It consists of three components:

Integration of this stack into the Open Data Hub is owned by the Distributed Workloads Working Group. See [this page](https://github.com/opendatahub-io/opendatahub-community/tree/master/wg-distributed-workloads) for further details and how to get in touch.

### Compatibilty Matrix
<!-- Don't delete these comments, they are used to generate Compatibility Matrix table for release automation -->
<!-- Compatibility Matrix start -->
### Compatibility Matrix

| Component | Version |
|------------------------------|---------|
Expand All @@ -25,6 +27,7 @@ Integration of this stack into the Open Data Hub is owned by the Distributed Wor
| CodeFlare-SDK | v0.6.1 |
| InstaScale | v0.0.6 |
| KubeRay | v0.5.0 |
<!-- Compatibility Matrix end -->

## Quick Start

Expand Down
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

go 1.20
go 1.19

0 comments on commit ea8f527

Please sign in to comment.