diff --git a/action.yml b/action.yml index cfe4ba3..a934f7c 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -138,7 +153,9 @@ 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: | @@ -146,10 +163,11 @@ runs: 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 ' @@ -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) @@ -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)