gh-pages-newtag #23
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
name: New Tag | |
on: | |
workflow_dispatch: | |
inputs: | |
tagname: | |
description: 'Specify Tag name to create/update.' | |
required: true | |
default: '2021-12-10-01-Q4' | |
ref: | |
description: 'Specify Git Ref if needed.' | |
required: false | |
default: 'refs/heads/main' | |
repository_dispatch: | |
types: [gh-pages-newtag] | |
# sample cURL | |
# curl --verbose -X POST https://api.github.com/repos/<github_user>/weblogic-azure/dispatches -H 'Accept: application/vnd.github.everest-preview+json' -H 'Authorization: token <personal_access_token>' --data '<request_data>' | |
# sample <request_data> | |
# {"event_type": "gh-pages-newtag", "client_payload": {"tagname": "2021-12-09-02-Q4", "ref": "refs/heads/main" }} | |
env: | |
tagbranch: "tagbranch" | |
gitToken: ${{ secrets.GIT_TOKEN }} | |
repoName: "weblogic-azure" | |
userEmail: ${{ secrets.USER_EMAIL }} | |
userName: ${{ secrets.USER_NAME }} | |
repoOwner: ${{ secrets.USER_NAME }} | |
jobs: | |
newtag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup environment variables | |
id: setup-env-variables-based-on-dispatch-event | |
run: | | |
if [ ${{ github.event_name }} == 'workflow_dispatch' ]; then | |
tagname=${{ github.event.inputs.tagname }} | |
ref=${{ github.event.inputs.ref }} | |
else | |
tagname=${{ github.event.client_payload.tagname }} | |
ref=${{ github.event.client_payload.ref }} | |
fi | |
if [ -z "$tagname" ]; then | |
tagname=${userName}`date +%m%d` | |
fi | |
if [ -z "$ref" ]; then | |
ref='refs/heads/main' | |
fi | |
echo "##[set-output name=tagname;]${tagname}" | |
echo "##[set-output name=ref;]${ref}" | |
echo "tagname=${tagname}" >> $GITHUB_ENV | |
echo "ref=${ref}" >> $GITHUB_ENV | |
- uses: actions/checkout@v2.3.4 | |
- name: Set up Maven with GitHub token | |
uses: ./.github/actions/setupmaven | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/checkout@v2.3.4 | |
- name: Set dependency reference | |
uses: ./.github/actions/setvars | |
with: | |
varFilePath: ./.github/variables/vm-dependencies.env | |
- name: Get versions of external dependencies | |
id: get-external-dependencies-version | |
run: | | |
curl -Lo external-deps-versions.properties https://raw.githubusercontent.com/Azure/azure-javaee-iaas/main/external-deps-versions.properties | |
source external-deps-versions.properties | |
echo "bicepVersion=${BICEP_VERSION}" >> $GITHUB_ENV | |
- name: Checkout ${{ env.repoName }} | |
uses: actions/checkout@v2 | |
with: | |
path: ${{ env.repoName }} | |
ref: ${{ env.ref }} | |
token: ${{ env.gitToken }} | |
- name: Checkout arm-ttk | |
uses: actions/checkout@v2 | |
with: | |
repository: Azure/arm-ttk | |
path: arm-ttk | |
ref: ${{ env.refArmttk }} | |
- name: Set up bicep | |
run: | | |
curl -Lo bicep https://github.com/Azure/bicep/releases/download/${bicepVersion}/bicep-linux-x64 | |
chmod +x ./bicep | |
sudo mv ./bicep /usr/local/bin/bicep | |
bicep --version | |
- name: Build ${{ env.repoName }} | |
run: | | |
cd ${{ env.repoName }} | |
mvn -Ptemplate-validation-tests clean install --file weblogic-azure-vm/pom.xml -Dgit.repo.owner=${{ env.repoOwner }} -Dgit.tag=${{ env.ref }} | |
mvn -Ptemplate-validation-tests -Pbicep clean install --file weblogic-azure-aks/pom.xml -Dgit.repo.owner=${{ env.repoOwner }} -Dgit.tag=${{ env.ref }} | |
ls weblogic-azure-aks/target/bicep | |
bicep build weblogic-azure-aks/target/bicep/mainTemplate.bicep --outfile weblogic-azure-aks/src/main/arm/mainTemplate.json | |
bicep build weblogic-azure-aks/target/bicep/modules/setupDBConnection.bicep --outfile weblogic-azure-aks/src/main/arm/dbTemplate.json | |
bicep build weblogic-azure-aks/target/bicep/modules/updateWebLogicApplications.bicep --outfile weblogic-azure-aks/src/main/arm/updateAppTemplate.json | |
- name: Create new tag | |
run: | | |
cd ${{ env.repoName }} | |
git config --global core.longpaths true | |
git config --global user.email $userEmail | |
git config --global user.name $userName | |
authGitPath=https://$gitToken@github.com/${GITHUB_REPOSITORY}.git | |
echo "Create tag branch" | |
remoteBranches=$(git ls-remote --heads) | |
echo ${remoteBranches} | |
if [[ -n `echo ${remoteBranches} | grep "${tagbranch}"` ]]; then | |
git push ${authGitPath} --delete ${tagbranch} -f | |
fi | |
if [[ -n `git branch --all | grep "${tagbranch}"` ]]; then | |
git branch -D ${tagbranch} | |
fi | |
git checkout -b ${tagbranch} | |
# replace pids | |
list=$(find weblogic-azure-vm -name "*.json" | grep "\/target\/") | |
for file in ${list}; do | |
sourcePath=$(echo "$file" | sed "s:target:src/main:g") | |
if test -f "$sourcePath"; then | |
echo "Replace ${sourcePath} with ${file}" | |
cp -f $file $sourcePath | |
fi | |
done | |
git status | |
git add --all | |
git commit -m "hard code pids" | |
git fetch --unshallow | |
git push ${authGitPath} ${tagbranch} -f | |
# remove existing tag | |
if [[ -n `git ls-remote --tags | grep "${tagname}"` ]]; then | |
git push ${authGitPath} --delete ${tagname} -f | |
fi | |
# create new tag | |
git tag ${tagname} | |
git push ${authGitPath} ${tagname} -f | |
git remote add upstream $gitToken@github.com:oracle/weblogic-azure.git | |
# ignore the error if cannot push, but log it | |
push_upstream_ignore_failure () { echo "push upstream result: $?" return 0; } | |
git push upstream ${tagname} -f || push_upstream_ignore_failure | |
git push ${authGitPath} --delete ${tagbranch} -f |