Skip to content

Add github actions to aid the release process (#557) #1

Add github actions to aid the release process (#557)

Add github actions to aid the release process (#557) #1

# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# This Github action keeps the CSM release branch up to date with main branch
name: Sync Release Branch with Main
on:
push:
branches:
- main
jobs:
rebase-branch:
runs-on: ubuntu-latest
env:
target-branch: "release-v1.13.0"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
- name: Fetch all branches
run: git fetch --all
- name: Rebase release branch with main
id: rebase
run: |
git checkout ${{ env.target-branch }}
git rebase main
- name: Push rebase changes to new branch
if: ${{ success() && steps.rebase.outcome == 'success' }}
run: |
git checkout -b rebase-feature-branch
git push origin rebase-feature-branch
# Needed for signing commits using Github App tokens
# See: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#commit-signing
- uses: actions/create-github-app-token@v1.11.0
id: generate-token
if: ${{ success() && steps.rebase.outcome == 'success' }}
with:
app-id: ${{ vars.CSM_RELEASE_APP_ID }}
private-key: ${{ secrets.CSM_RELEASE_APP_PRIVATE_KEY }}
- name: Create pull request
if: ${{ success() && steps.rebase.outcome == 'success' }}
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.generate-token.outputs.token }}
branch: rebase-feature-branch
base: ${{ env.target-branch }}
title: 'Rebase release branch with main'
body: |
This PR rebases the release branch with the main branch.
Auto-generated by [dell/helm-charts](https://github.com/dell/helm-charts)
sign-commits: true
commit-message: "Rebase release branch with main"
- name: Get PR author
if: ${{ failure() && steps.rebase.outcome == 'failure' }}
id: get_pr_author
uses: actions/github-script@v7
with:
script: |
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
base: 'main',
sort: 'updated',
direction: 'desc',
per_page: 1
});
const lastMergedPR = pulls.find(pr => pr.merged_at !== null);
if (!lastMergedPR) {
throw new Error('No merged pull request found.');
}
const author = lastMergedPR.user.login;
if (!author) {
throw new Error('No author found.');
}
core.setOutput('author', author);
console.log(`Author: ${author}`);
- name: Set PR author output
if: ${{ failure() && steps.rebase.outcome == 'failure' }}
run: |
echo "PR_AUTHOR=${{ steps.get_pr_author.outputs.author }}" >> $GITHUB_ENV
- name: Create issue for rebase conflict
if: ${{ failure() && steps.rebase.outcome == 'failure' }}
uses: actions/github-script@v7
with:
script: |
const PR_AUTHOR = process.env.PR_AUTHOR;
if (!PR_AUTHOR) {
throw new Error('PR_AUTHOR environment variable is not set.');
}
const issueTitle = `Rebase conflict on ${{ env.target-branch }} branch`;
const issueBody = `There was a conflict rebasing the ${{ env.target-branch }} branch onto main. Please resolve the conflicts manually. See [Sync Release Branch with Main action](https://github.com/shaynafinocchiaro/helm-charts-test/actions/workflows/rebase-release.yml) for more details.`;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody,
assignees: [PR_AUTHOR],
});