Skip to content

Commit

Permalink
create automate pr for release
Browse files Browse the repository at this point in the history
  • Loading branch information
apham0001 committed Oct 2, 2024
1 parent 8876c3c commit 3242425
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 12 deletions.
95 changes: 83 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,86 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Disable shallow checkout
- uses: ./.github/actions/setup-go
- run: go run . --help > cli-reference.txt
- run: go run testutil/genchangelog/main.go
- uses: softprops/action-gh-release@v1
with:
draft: true
files: cli-reference.txt
body_path: changelog.md
token: ${{ secrets.RELEASE_SECRET }}
- name: Checkout repository
uses: actions /checkout@v4
with:
fetch-depth: 0 # Disable shallow checkout

- name: Setup Go environment
uses: ./.github/actions/setup-go

- name: Generate CLI reference
run: go run . --help > cli-reference.txt

- name: Generate changelog
run: go run testutil/genchangelog/main.go

- name: Create GitHub release draft
uses: softprops/action-gh-release@v1
with:
draft: true
files: cli-reference.txt
body_path: changelog.md
token: ${{ secrets.RELEASE_SECRET }}

extract-tag:
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.get_tag_name.outputs.tag_name }}
steps:
- name: Extract tag name
id: get_tag_name
run: echo "::set-output name=tag_name::${GITHUB_REF##*/}"

create-pr-obol-infrastructure:
runs-on: ubuntu-latest
needs: extract-tag
uses: ./.github/workflows/update-version-pr.yml
with:
repository: ObolNetwork/obol-infrastructure.git
path: obol-infrastructure
file_changes_script: |
sed -i 's/default = "v[0-9.]*"/default = "'${{ needs.extract-tag.outputs.tag_name#v }}'"/g' performance-cluster/variables.tf
base_branch: main

create-pr-helm:
runs-on: ubuntu-latest
needs: extract-tag
uses: ./.github/workflows/update-version-pr.yml
with:
repository: ObolNetwork/helm-charts.git
path: helm-charts
file_changes_script: |
increment_version() {
echo "$1" | awk -F. '{printf "%d.%d.%d", $1, $2, $3+1}'
}
# Update charon-cluster Chart.yaml
CHART_CLUSTER_VERSION=$(grep '^version:' charts/charon-cluster/Chart.yaml | awk '{print $2}')
NEW_CHART_CLUSTER_VERSION=$(increment_version $CHART_CLUSTER_VERSION)
sed -i "s/^version: .*/version: ${NEW_CHART_CLUSTER_VERSION}/" charts/charon-cluster/Chart.yaml
sed -i "s/^appVersion: .*/appVersion: \"${{ needs.extract-tag.outputs.tag_name#v }}\"/" charts/charon-cluster/Chart.yaml
# Update charon-cluster values.yaml
sed -i "/tag:/s/v[0-9.]*$/v${{ needs.extract-tag.outputs.tag_name#v }}/" charts/charon-cluster/values.yaml
# Update charon Chart.yaml
CHART_VERSION=$(grep '^version:' charts/charon/Chart.yaml | awk '{print $2}')
NEW_CHART_VERSION=$(increment_version $CHART_VERSION)
sed -i "s/^version: .*/version: ${NEW_CHART_VERSION}/" charts/charon/Chart.yaml
sed -i "s/^appVersion: .*/appVersion: \"${{ needs.extract-tag.outputs.tag_name#v }}\"/" charts/charon/Chart.yaml
# Update charon values.yaml
sed -i "/tag:/s/v[0-9.]*$/v${{ needs.extract-tag.outputs.tag_name#v }}/" charts/charon/values.yaml
base_branch: main

create-pr-obol-ansible:
runs-on: ubuntu-latest
needs: extract-tag
uses: ./.github/workflows/update-version-pr.yml
with:
repository: ObolNetwork/obol-ansible.git
path: obol-ansible
file_changes_script: |
sed -i "s/^node_image_version: 'v[0-9.]*'/node_image_version: 'v${{ needs.extract-tag.outputs.tag_name#v }}'/" group_vars/all.yml
base_branch: main
65 changes: 65 additions & 0 deletions .github/workflows/update-version-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Update Version and Create PR

on:
workflow_call:
inputs:
repository:
required: true
type: string
description: 'The target repository for the PR.'
path:
required: true
type: string
description: 'The path to check out the repository.'
file_changes_script:
required: true
type: string
description: 'The script to make file changes.'
base_branch:
required: true
type: string
description: 'The base branch to create the PR against.'

jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v4

- name: Setup SSH for Git operations
run: |
mkdir -p ~/.ssh
echo "${{ secrets.OBOL_PLATFORM_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Checkout target repository
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ssh-key: ${{ secrets.OBOL_PLATFORM_SSH_KEY }}
path: ${{ inputs.path }}

- name: Make changes in target repository
run: |
cd ${{ inputs.path }}
${{ inputs.file_changes_script }}
# Commit and push changes
git config user.name "obol-platform"
git config user.email "obol-platform@users.noreply.github.com"
git checkout -b update-version-${{ github.event.inputs.tag_name }}
git add .
git commit -m "Update version to ${{ github.event.inputs.tag_name }}"
git push origin update-version-${{ github.event.inputs.tag_name }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.OBOL_PLATFORM_PAT }}
repository: ${{ inputs.repository }}
base: ${{ inputs.base_branch }}
head: update-version-${{ github.event.inputs.tag_name }}
title: "Update version to ${{ github.event.inputs.tag_name }}"
body: "Automatically generated PR to update version to ${{ github.event.inputs.tag_name }}"

0 comments on commit 3242425

Please sign in to comment.