-
Notifications
You must be signed in to change notification settings - Fork 2
169 lines (145 loc) · 6.12 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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: cbanh/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 }}
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
fi
- name: Append text to file (${{ env.SWODLR_SOURCE_REPO }})
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 }}