Skip to content

Build and Deploy

Build and Deploy #138

Workflow file for this run

name: Build and Deploy
on:
push:
branches:
- 'master'
tags-ignore:
- '*'
paths-ignore:
- 'package.json'
- 'package-lock.json'
- 'bumpver.toml'
# For manual build/deployment
workflow_dispatch:
inputs:
venue:
type: choice
description: Venue to deploy to
options:
- UAT
- OPS
source_branch:
type: string
description: Source branch
target_branch:
type: string
description: Target branch
deploy_latest_ops:
type: boolean
description: Source branches is from latest release UAT branches. Only used for OPS.
commit:
type: string
description: Custom commit hash
permissions:
contents: read
packages: read
jobs:
Deploy_SWODLR_UI:
name: Deploy SWODLR-UI
runs-on: ubuntu-latest
env:
SWODLR_SOURCE_REPO: podaac/swodlr-ui
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 }}
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 }}
Deploy_SWODLR_Ingest_to_SDS:
name: Deploy SWODLR-Ingest_to_SDS
runs-on: ubuntu-latest
env:
SWODLR_SOURCE_REPO: podaac/swodlr-ingest-to-sds
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 }}
Deploy_SWODLR_Raster_Create:
name: Deploy SWODLR Raster Create
runs-on: ubuntu-latest
env:
SWODLR_SOURCE_REPO: podaac/swodlr-raster-create
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 }}
Deploy_SWODLR_Async_Update:
name: Deploy SWODLR Async Update
runs-on: ubuntu-latest
env:
SWODLR_SOURCE_REPO: podaac/swodlr-async-update
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 }}
Deploy_SWODLR_USER_NOTIFY:
name: Deploy SWODLR User Notify
runs-on: ubuntu-latest
env:
SWODLR_SOURCE_REPO: podaac/swodlr-user-notify
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 }}