Skip to content

Commit

Permalink
added swodlr-api
Browse files Browse the repository at this point in the history
  • Loading branch information
cqbanh committed Mar 14, 2024
1 parent db3aa7e commit bfa2bc0
Showing 1 changed file with 138 additions and 1 deletion.
139 changes: 138 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ jobs:
VENUE: ${{ github.event.inputs.venue }}
SOURCE_BRANCH: ${{ github.event.inputs.source_branch }}
TARGET_BRANCH: ${{ github.event.inputs.target_branch }}
DEPLOY_LATEST_OPS: ${{ github.event.inputs.deploy_latest_ops }}
DEPLOY_LATEST_OPS: ${{ github.event.inputs.deploy_latest_ops }}
NEW_BRANCH: false

steps:
- name: Init Setup for UAT
Expand Down Expand Up @@ -159,11 +160,147 @@ jobs:
# Push the new branch to the remote repository
git push origin $TARGET_BRANCH
echo "NEW_BRANCH=true" >> $GITHUB_ENV
fi
- name: Append text to file (${{ env.SWODLR_SOURCE_REPO }})
if: env.NEW_BRANCH == 'true'
run: |
echo "${{ env.SWODLR_SOURCE_REPO }} deployment ${{ github.event.inputs.commit }}" >> CHANGE
git add CHANGE
git commit -m "Deploying ${{ github.event.inputs.commit }}"
git push origin ${{ env.TARGET_BRANCH }}
Deploy_SWODLR_API:
name: Deploy SWODLR-API
runs-on: ubuntu-latest

env:
SWODLR_SOURCE_REPO: podaac/swodlr-api
VENUE: ${{ github.event.inputs.venue }}
SOURCE_BRANCH: ${{ github.event.inputs.source_branch }}
TARGET_BRANCH: ${{ github.event.inputs.target_branch }}
DEPLOY_LATEST_OPS: ${{ github.event.inputs.deploy_latest_ops }}
NEW_BRANCH: false

steps:
- name: Init Setup for UAT
if: ${{ env.VENUE == 'UAT' }}
run: |
echo "Venue: ${{ env.VENUE }}"
echo "SOURCE_BRANCH=develop" >> $GITHUB_ENV
- name: Init Setup for OPS
if: ${{ env.VENUE == 'OPS' }}
run: |
echo "Venue: ${{ env.VENUE }}"
echo "TARGET_BRANCH=main" >> $GITHUB_ENV
if [[ -z "${{ env.SOURCE_BRANCH }}" ]]; then
echo "SOURCE_BRANCH=main" >> $GITHUB_ENV
else
echo "SOURCE_BRANCH is: ${{ env.SOURCE_BRANCH }}"
fi
- uses: getsentry/action-github-app-token@v2
name: my-app-install token
id: podaac-cicd
with:
app_id: ${{ secrets.CICD_APP_ID }}
private_key: ${{ secrets.CICD_APP_PRIVATE_KEY }}

- name: Checkout source repository
uses: actions/checkout@v2
with:
repository: ${{ env.SWODLR_SOURCE_REPO }}
ref: ${{ env.SOURCE_BRANCH }} # The branch you want to base the new branch on
token: ${{ steps.podaac-cicd.outputs.token }}

- name: Set up Git in source repository
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
# TARGET_BRANCH is null (redeploy)
- name: Set UAT branch
if: ${{ env.VENUE == 'UAT' && !github.event.inputs.target_branch }}
run: |
# Fetch branches from the remote repository
git fetch origin
git branch -a
latest_release_branch=$(git branch -a | grep -Eo 'release/[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1)
echo "latest_release_branch=$latest_release_branch" >> $GITHUB_ENV
echo "TARGET_BRANCH=$latest_release_branch" >> $GITHUB_ENV
echo "SOURCE_BRANCH=$latest_release_branch" >> $GITHUB_ENV
- name: Set OPS branch
if: ${{ env.VENUE == 'OPS' && github.event.inputs.deploy_latest_ops == 'true' }}
run: |
# Fetch branches from the remote repository
git fetch origin
git branch -a
latest_release_branch=$(git branch -a | grep -Eo 'release/[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1)
echo "latest_release_branch=$latest_release_branch" >> $GITHUB_ENV
echo "SOURCE_BRANCH=$latest_release_branch" >> $GITHUB_ENV
- name: Debug
run: |
echo "deploy_latest_ops: ${{ github.event.inputs.deploy_latest_ops }}"
echo "The latest release branch is: ${{ env.latest_release_branch }}"
echo "The target branch is: $TARGET_BRANCH"
echo "The source branch is: $SOURCE_BRANCH"
- name: Checkout source repository
uses: actions/checkout@v2
with:
repository: ${{ env.SWODLR_SOURCE_REPO }}
ref: ${{ env.SOURCE_BRANCH }} # The branch you want to base the new branch on
token: ${{ steps.podaac-cicd.outputs.token }}

- name: Create and push to target branch in target repository (SWODLR-UI)
run: |
ACCESS_TOKEN=${{ steps.podaac-cicd.outputs.token }}
TARGET_BRANCH=${{ env.TARGET_BRANCH }}
# Fetch branches from the remote repository
git fetch origin
# Check if the branch already exists remotely
if git show-ref --quiet --verify "refs/remotes/origin/$TARGET_BRANCH"; then
echo "Branch $TARGET_BRANCH already exists remotely. Checking out existing branch."
git checkout $TARGET_BRANCH
git pull origin $TARGET_BRANCH --no-rebase --allow-unrelated-histories
# Merge changes from the source branch, auto-resolve conflicts
git merge -s recursive -Xtheirs --no-commit ${{ env.SOURCE_BRANCH }} --allow-unrelated-histories
# Check if there are changes to commit
if ! git diff --cached --exit-code; then
# # Take target changes for package.json, package-lock.json, and CHANGE
# git checkout --ours -- package.json package-lock.json CHANGE
# Commit the changes
git commit -m "Merge changes from source branch, auto-resolving conflicts"
# Push the changes to the remote branch
git push origin $TARGET_BRANCH
else
echo "No changes to commit."
fi
else
echo "Branch $TARGET_BRANCH does not exist remotely. Creating and pushing the new branch."
git checkout -b $TARGET_BRANCH
# Push the new branch to the remote repository
git push origin $TARGET_BRANCH
echo "NEW_BRANCH=true" >> $GITHUB_ENV
fi
- name: Append text to file (${{ env.SWODLR_SOURCE_REPO }})
if: env.NEW_BRANCH == 'true'
run: |
echo "${{ env.SWODLR_SOURCE_REPO }} deployment ${{ github.event.inputs.commit }}" >> CHANGE
git add CHANGE
git commit -m "Deploying ${{ github.event.inputs.commit }}"
git push origin ${{ env.TARGET_BRANCH }}

0 comments on commit bfa2bc0

Please sign in to comment.