-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
set -x | ||
|
||
if [ -z "$INPUT_SOURCE_FOLDER" ] | ||
then | ||
echo "Source folder must be defined" | ||
return -1 | ||
fi | ||
|
||
if [ $INPUT_DESTINATION_HEAD_BRANCH == "main" ] || [ $INPUT_DESTINATION_HEAD_BRANCH == "master"] | ||
then | ||
echo "Destination head branch cannot be 'main' nor 'master'" | ||
return -1 | ||
fi | ||
|
||
if [ -z "$INPUT_PULL_REQUEST_REVIEWERS" ] | ||
then | ||
PULL_REQUEST_REVIEWERS=$INPUT_PULL_REQUEST_REVIEWERS | ||
else | ||
PULL_REQUEST_REVIEWERS='-r '$INPUT_PULL_REQUEST_REVIEWERS | ||
fi | ||
|
||
CLONE_DIR=$(mktemp -d) | ||
|
||
echo "Setting git variables" | ||
export GITHUB_TOKEN=$API_TOKEN_GITHUB | ||
git config --global user.email "$INPUT_USER_EMAIL" | ||
git config --global user.name "$INPUT_USER_NAME" | ||
|
||
echo "Cloning destination git repository" | ||
git clone "https://$API_TOKEN_GITHUB@github.com/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR" | ||
|
||
echo "Copying contents to git repo"-r $INPUT_USER_NAME | ||
cp -R $INPUT_SOURCE_FOLDER "$CLONE_DIR/$INPUT_DESTINATION_FOLDER" | ||
cd "$CLONE_DIR" | ||
git checkout -b "$INPUT_DESTINATION_HEAD_BRANCH" | ||
|
||
echo "Adding git commit" | ||
git add . | ||
if git status | grep -q "Changes to be committed" | ||
then | ||
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" | ||
echo "Pushing git commit" | ||
git push -u origin HEAD:$INPUT_DESTINATION_HEAD_BRANCH | ||
echo "Creating a pull request" | ||
gh pr create -t $INPUT_DESTINATION_HEAD_BRANCH \ | ||
-b $INPUT_DESTINATION_HEAD_BRANCH \ | ||
-B $INPUT_DESTINATION_BASE_BRANCH \ | ||
-H $INPUT_DESTINATION_HEAD_BRANCH \ | ||
$PULL_REQUEST_REVIEWERS | ||
else | ||
echo "No changes detected" | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ env: | |
|
||
jobs: | ||
deployment: | ||
name: Deployment | ||
name: Create deployment PR | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
|
@@ -50,14 +50,13 @@ jobs: | |
cat ${{ env.DEPLOYMENT_SCRIPTS_REPO }}/${{ env.SERVICE_RESOURCES_FILE }} |\ | ||
./hcledit attribute set locals.svc_${{ steps.service-name.outputs.service_name }}_image_version '"${{ inputs.service_image_tag }}"' \ | ||
> ${{ env.SERVICE_RESOURCES_FILE }} | ||
- name: Create pull request | ||
uses: paygoc6/[email protected] | ||
- name: Create deployment pull request | ||
env: | ||
API_TOKEN_GITHUB: ${{ secrets.api_github_token }} | ||
with: | ||
source_folder: "terraform-plans" | ||
destination_repo: ${{ env.DEPLOYMENT_SCRIPTS_REPO }} | ||
destination_base_branch: 'main' | ||
destination_head_branch: cd/${{ inputs.environment }}/${{ github.event.repository.name }}/${{ inputs.service_image_tag }} | ||
user_email: ${{ github.event.pusher.email }} | ||
user_name: ${{ github.actor }} | ||
INPUT_SOURCE_FOLDER: "terraform-plans" | ||
INPUT_DESTINATION_REPO: ${{ env.DEPLOYMENT_SCRIPTS_REPO }} | ||
INPUT_DESTINATION_BASE_BRANCH: "main" | ||
INPUT_DESTINATION_HEAD_BRANCH: cd/${{ inputs.environment }}/${{ github.event.repository.name }}/${{ inputs.service_image_tag }} | ||
INPUT_USER_EMAIL: ${{ github.event.pusher.email }} | ||
INPUT_USER_NAME: ${{ github.actor }} | ||
run: "${GITHUB_WORKSPACE}/.github/create-pr.sh" |
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