Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbl committed Apr 21, 2024
1 parent 900237a commit 60d5a7c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 15 deletions.
55 changes: 55 additions & 0 deletions .github/create-pr.sh
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
19 changes: 9 additions & 10 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:

jobs:
deployment:
name: Deployment
name: Create deployment PR
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -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/action-pull-request-another-repo@v1.0.1
- 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"
15 changes: 10 additions & 5 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ on:
- '**'
tags:
- '*'

env:
AWS_REGION: us-west-2
NPM_GITHUB_TOKEN: ${{ secrets.API_TOKEN_GITHUB_PRIVATE_PACKAGES_DOWNLOAD }}

jobs:
integration:
Expand All @@ -17,11 +17,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install deps
run: yarn
- name: Lint
run: yarn lint
- name: Build
run: yarn build

run: yarn prisma generate && yarn build
docker-image:
if: ${{ !contains(github.ref, 'heads/dependabot') }}
needs:
Expand Down Expand Up @@ -56,14 +61,14 @@ jobs:
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ steps.get-image-tag.outputs.image_tag }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest --build-arg NPM_GITHUB_TOKEN=${{ secrets.API_TOKEN_GITHUB_PRIVATE_PACKAGES_DOWNLOAD }} .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
outputs:
image_tag: ${{ steps.get-image-tag.outputs.image_tag }}

cd_production:
# if: ${{ contains(github.ref, 'heads/master') }}
if: ${{ contains(github.ref, 'heads/main') || contains(github.ref, 'fix')}}
needs:
- docker-image
uses: ./.github/workflows/cd.yaml
Expand Down

0 comments on commit 60d5a7c

Please sign in to comment.