Merge pull request #25 from petercort/issue24 #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | |
owner: ${{ github.repository_owner }} | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Get new version | |
id: get_version | |
run: | | |
NEW_VERSION=$(cat app.version) | |
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
- name: Checkout FBF Config Repo | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository_owner }}/${{ secrets.deployment_repo }} | |
token: ${{ steps.app-token.outputs.token }} | |
- name: Create new branch and update image tag | |
env: | |
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: | | |
NEW_VERSION=${{ steps.get_version.outputs.new_version }} | |
BRANCH_NAME="release/${NEW_VERSION}" | |
# Create a new branch | |
git checkout -b $BRANCH_NAME | |
# Update the image.tag in values.yaml | |
sed -i "s/^appVersion: .*/appVersion: \"$NEW_VERSION\"/" event-buddy/Chart.yaml | |
git config --global user.name "${{ steps.app-token.outputs.app-slug }}[bot]" | |
git config --global user.email "${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>" | |
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: "${{ github.repository_owner }}", name: "${{ secrets.deployment_repo }}") { 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" |