Skip to content

Commit

Permalink
Create update-image-tag.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
petercort authored Dec 28, 2024
1 parent 651e172 commit 179d039
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/update-image-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Update Image Tag

on:
workflow_dispatch:
push:
branches:
- main
paths:
- app.version

jobs:
update-image-tag:
runs-on: ubuntu-latest

steps:
- name: Get app token
uses: actions/[email protected]
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}

- name: Checkout repository
uses: actions/checkout@v3

- name: Get new version
if: steps.check_version.outputs.version_changed == 'true'
id: get_version
working-directory: event-buddy
run: |
NEW_VERSION=$(grep '^appVersion:' app.version | awk '{print $2}')
echo "::set-output name=new_version::$NEW_VERSION"
- name: Create new branch and update image tag
if: steps.check_version.outputs.version_changed == 'true'
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
NEW_VERSION=${{ steps.get_version.outputs.new_version }}
BRANCH_NAME="release/${NEW_VERSION}"
# Clone the target repository
git clone https://github.com/petercort/fbf-event-buddy-config.git
cd fbf-event-buddy-config
# Create a new branch
git checkout -b $BRANCH_NAME
# Update the image.tag in values.yaml
sed "s/^appVersion: .*/appVersion: \"$new_version\"/" event-buddy/Chart.yaml
git add event-buddy/Chart.yaml
git commit -m "Update image tag to $NEW_VERSION"
git push origin $BRANCH_NAME
# Create a pull request using GitHub GraphQL API
PR_QUERY=$(cat <<EOF
mutation {
createPullRequest(input: {
repositoryId: "$(gh api graphql -f query='query { repository(owner: "your-username", name: "fbf-event-buddy-config") { id } }' -q .data.repository.id)"
title: "Update image tag to $NEW_VERSION"
headRefName: "$BRANCH_NAME"
baseRefName: "main"
body: "This PR updates the image tag to $NEW_VERSION."
maintainerCanModify: true
}) {
pullRequest {
url
}
}
}
EOF
)
gh api graphql -f query="$PR_QUERY"

0 comments on commit 179d039

Please sign in to comment.