Skip to content

Commit

Permalink
Merge pull request #2 from ditkrg/aggregate-prod-releases
Browse files Browse the repository at this point in the history
Aggregate production release PRs
  • Loading branch information
shkarface authored Dec 17, 2023
2 parents b4eb5e0 + 538c29c commit fedb158
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,26 @@ runs:

run: gh label create "$LABEL_NAME" --force --color "$LABEL_COLOR" --description "$LABEL_DESCRIPTION"

- name: Get branch name
id: get-branch-name
shell: bash
env:
TARGET_ENV: ${{ steps.get-environment.outputs.environment }}
run: |
if [ $TARGET_ENV == "production" ]; then
BRANCH_NAME="prod-release"
else
BRANCH_NAME=update-${{ steps.get-environment.outputs.environment }}-${{ inputs.component-name }}
fi
echo "TARGET_BRANCH=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Create branch if not exists
shell: bash
env:
TARGET_FILE: ${{ inputs.component-name }}/${{ steps.find-target-file.outputs.target_file }}
TARGET_BRANCH: update-${{ steps.get-environment.outputs.environment }}-${{ inputs.component-name }}
TARGET_BRANCH: ${{ steps.get-branch-name.outputs.TARGET_BRANCH }}
run: |
# Do not create a new branch if the branch already exists
Expand Down Expand Up @@ -138,18 +153,21 @@ runs:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
FULL_IMAGE_TAG: ${{ inputs.image-tag }}
TARGET_FILE: ${{ inputs.component-name }}/${{ steps.find-target-file.outputs.target_file }}
TARGET_BRANCH: update-${{ steps.get-environment.outputs.environment }}-${{ inputs.component-name }}
TARGET_BRANCH: ${{ steps.get-branch-name.outputs.TARGET_BRANCH }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_SERVER_URL: ${{ github.server_url }}
run: |
# Update the image.yaml file with the new image tag
echo "#########################################################################################" > $TARGET_FILE
echo "# This file was automatically generated by the auto-deploy action. Do not edit manually.#" >> $TARGET_FILE
echo -e "#########################################################################################\n" >> $TARGET_FILE
echo "#########################################################################################" >> $TARGET_FILE
echo "# GITHUB_REPOSITORY: $GITHUB_REPOSITORY" >> $TARGET_FILE
export IMAGE_TAG="${FULL_IMAGE_TAG##*:}" # Removes everything up to and including the last colon
export GITHUB_REPO_URL="${{ github.server_url }}/${{ github.repository }}"
export GITHUB_REPO_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
# Initialize the YAML output
yq -i '
Expand Down Expand Up @@ -184,7 +202,7 @@ runs:
LABEL_NAME: auto-deploy
TARGET_ENV: ${{ steps.get-environment.outputs.environment }}
TARGET_FILE: ${{ steps.find-target-file.outputs.target_file }}
HEAD_BRANCH: update-${{ steps.get-environment.outputs.environment }}-${{ inputs.component-name }}
HEAD_BRANCH: ${{ steps.get-branch-name.outputs.TARGET_BRANCH }}
IS_COMMIT: ${{ steps.commit.outputs.commit }}
run: |
# reset the local changes and pull changes from the remote branch (Because we are using the REST API to commit changes and not the git cli)
Expand All @@ -196,7 +214,9 @@ runs:
if [[ $(gh pr list --state open --base main --head $HEAD_BRANCH) ]]; then
echo "PR already exists"
else
if [ $TARGET_ENV == "production" ] || [ $TARGET_ENV == "staging" ]; then
if [ $TARGET_ENV == "production" ]; then
export pr_url=$(gh pr create --title "Production release" --body "Populating PR description with release notes :clock130: ..." --base main --head $HEAD_BRANCH)
elif [ $TARGET_ENV == "staging" ]; then
export pr_url=$(gh pr create --title "chore: Update ${{ inputs.component-name }} image tag in ${{ steps.get-environment.outputs.environment }}" --body "This PR was automatically created by the auto-deploy action" --base main --head $HEAD_BRANCH)
else
export pr_url=$(gh pr create --title "chore: Update ${{ inputs.component-name }} image tag in ${{ steps.get-environment.outputs.environment }}" --body "This PR was automatically created by the auto-deploy action" --base main --head $HEAD_BRANCH --label $LABEL_NAME)
Expand Down

0 comments on commit fedb158

Please sign in to comment.