Skip to content

Build and Push Final Image Tag #40

Build and Push Final Image Tag

Build and Push Final Image Tag #40

name: Build and Push Final Image Tag
on:
workflow_dispatch:
inputs:
Tag:
description: "Final Image Tag to Deploy to docker hub"
default: "1.1.1"
type: string
PreviousTag:
description: "Previously Deployed Final Image Tag"
default: "1.1.1"
type: string
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:
id-token: write
contents: write
jobs:
Build_And_Push_Final_Image:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
ref: "main"
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y install zip
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: "arn:aws:iam::472613559203:role/github-actions-repo-integration-docker-final-images-role"
aws-region: us-east-1
- name: Download Agent
run: |
./bin/download.sh ${{ github.event.inputs.Tag }}
- name: Update the Templates and Copy Template Into Agents
run: |
./bin/copy.sh ${{ github.event.inputs.Tag }} ${{ github.event.inputs.PreviousTag }}
- name: Build and zip the new Agents
run: |
./bin/build.sh ${{ github.event.inputs.Tag }}
- name: Push new zips to S3
run: |
aws s3 cp "tmp/agent-4-github-enterprise-${{ github.event.inputs.Tag }}-with-prebuilt.zip" "s3://wsd-integration/release/Agent-for-GitHub-Enterprise/agent-4-github-enterprise-${{ github.event.inputs.Tag }}-with-prebuilt.zip"
- name: 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