Skip to content

PR to update Charts #24

PR to update Charts

PR to update Charts #24

name: PR to update Charts
# This action will run automatically after the workflow "Publish container" is completed
on:
workflow_run:
workflows: ["Publish container"]
types:
- completed
workflow_dispatch:
permissions:
contents: read
env:
LATEST_HEADLAMP_TAG: latest
jobs:
create_pr_to_upgrade_chart:
name: Create PR to update Headlamp's version in the Helm Chart
runs-on: ubuntu-latest
permissions:
contents: write # needed to push a branch
pull-requests: write # needed to open a pull request
steps:
- name: Checkout headlamp repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
user=${{github.actor}}
if [ -z $user ]; then
user=joaquimrocha
fi
git config --global user.name "$user"
git config --global user.email "$user@users.noreply.github.com"
- name: Get headlamp latest tag
run: |
latestTag=$(git tag --list --sort=version:refname 'v*' | tail -1)
echo "LATEST_HEADLAMP_TAG=$latestTag" >> $GITHUB_ENV
echo $latestTag
- name: Update Headlamp version in charts
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ -z $user ]; then
user=joaquimrocha
fi
# Extract current version
CURRENT_CHART_VERSION=$(grep '^version:' ./charts/headlamp/Chart.yaml | cut -d' ' -f2)
CURRENT_CHART_VERSION=$(echo $CURRENT_CHART_VERSION | awk -F. -v OFS=. '{$(NF - 1) += 1 ; print}')
# Create branch
BRANCH=update_chart_headlamp_$LATEST_HEADLAMP_TAG
if git branch -l | grep -q $BRANCH; then
echo "deleting old branch from local to avoid conflict"
git branch -D $BRANCH
fi
if git branch -a | grep -q "origin/$BRANCH"; then
echo "deleting old branch from remote to avoid conflict"
git push origin --delete "$BRANCH"
fi
# Move to new branch
git checkout -b $BRANCH
sed -i "s/^version:\ .*/version: $CURRENT_CHART_VERSION/g" ./charts/headlamp/Chart.yaml
# Replace the app version by the headlamp tag but discarding the first char (v)
sed -i "s/^appVersion:\ .*/appVersion: ${LATEST_HEADLAMP_TAG:1}/g" ./charts/headlamp/Chart.yaml
git diff
git status
git add ./charts/headlamp/Chart.yaml
git commit --signoff -m "charts: Bump Headlamp version to $LATEST_HEADLAMP_TAG"
git status
git log -1
git push origin $BRANCH -f
gh pr create \
--title "chart: Bump Headlamp version to $LATEST_HEADLAMP_TAG" \
--base "main" \
--assignee "$user" \
--body "Automatically opened by CI."