Skip to content

Build and Push From Repo Integration Version #25

Build and Push From Repo Integration Version

Build and Push From Repo Integration Version #25

name: Build and Push From Repo Integration Version
on:
workflow_dispatch:
inputs:
Tag:
description: "Tag: Repo Integration Version to pull, build, and push."
default: "1.1.1"
type: string
required: true
IsLatest:
description: "IsLatest: (default true) If True, release branch will be merged back into main and release will be set as latest."
default: true
type: boolean
SkipGit:
description: "SkipGit: (default false) If True, no changes will be made to repo. However, the new images will still be pushed to Docker Hub!"
default: false
type: boolean
permissions:
contents: write
jobs:
Build_And_Push_Base_Image_From_Version:
runs-on: [ mend-self-hosted, profile=developer-platform-xlarge ]
steps:
- name: Check out code
uses: actions/checkout@v3
with:
ref: "main"
fetch-depth: 0
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Download Agent
run: |
./bin/download.sh ${{ github.event.inputs.Tag }}
- name: Copy Agent Files
run: |
./bin/copy.sh ${{ github.event.inputs.Tag }}
- name: Build Docker Images
run: |
./bin/build.sh ${{ github.event.inputs.Tag }}
- name: Publish to Docker Hub
run: |
./bin/publish.sh ${{ github.event.inputs.Tag }}
- name: Branch, Commit, Push and Tag Changes
env:
GH_TOKEN: ${{ github.token }}
run: |
# If SkipGet is true, don't modify repo
if [ "${{ github.event.inputs.SkipGit }}" = true ]; then
echo "SkipGit is true, skipping git changes"
exit 0
fi
# Note: using Github
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Create Release branch
git checkout -b release/${{ github.event.inputs.Tag }}
git push --set-upstream origin release/${{ github.event.inputs.Tag }}
# If files changed, add, commit and push
if [[ `git status --porcelain` ]]; then
echo "OK: Changes detected, committing and pushing."
git add .
git commit -m "Saving new files for ${{ github.event.inputs.Tag }}"
git push
else
echo "WARNING: No changes were detected. This is fine though, skipping commit"
fi
# Create tag
git tag -a ${{ github.event.inputs.Tag }} -m "Automated Tag for Release ${{ github.event.inputs.Tag }}"
git push origin --tags
# Create release
if [ "${{ github.event.inputs.IsLatest }}" = false ]; then
gh release create "${{ github.event.inputs.Tag }}" --latest=false --generate-notes --target release/${{ github.event.inputs.Tag }} --title "${{ github.event.inputs.Tag }}"
echo "IsLatest is false, not merging release branch back into main"
exit 0
else
gh release create "${{ github.event.inputs.Tag }}" --latest --generate-notes --target release/${{ github.event.inputs.Tag }} --title "${{ github.event.inputs.Tag }}"
fi
# Merge release branch back into main
git checkout main
git merge release/${{ github.event.inputs.Tag }} --commit --no-edit
git push
shell: bash