ci #301
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: ci | |
on: | |
push: | |
branches: [main] | |
schedule: | |
- cron: '0 0 * * 0' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Git Global Conf | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
git config --global push.autoSetupRemote true | |
- id: get-sha | |
run: | | |
git_sha=$(git log -1 --pretty=format:"%H") | |
echo "git_commit_id=${git_sha}" >> $GITHUB_ENV | |
- id: new-branch-name | |
run: | | |
BRANCH_NAME=feature/new-ami-release-$(date +"%m-%d-%y")-${{ env.git_commit_id }} | |
echo "new_branch_name=${BRANCH_NAME}" >> $GITHUB_ENV | |
- name: Git new Branch | |
run: | | |
git fetch --all | |
exists=`git ls-remote --heads origin ${{ env.new_branch_name }};` | |
if [ -n "$exists" ]; then | |
echo "Branch ${{ env.new_branch_name }} Exists..." | |
git checkout --track origin/${{ env.new_branch_name }} | |
else | |
echo "Branch " + ${{ env.new_branch_name }} + " Does not Exists..." | |
git checkout -b ${{ env.new_branch_name }} | |
fi | |
- name: Apply new changes | |
run: | | |
wget -O new-amazon-eks-ami-main.zip "https://github.com/awslabs/amazon-eks-ami/archive/refs/heads/main.zip" | |
unzip new-amazon-eks-ami-main.zip | |
rm -rf ./new-amazon-eks-ami-main.zip | |
rm -rf ./amazon-eks-ami-main/.git | |
rm -rf ./amazon-eks-ami-main/.github | |
rm -rf ./amazon-eks-ami/ | |
mv ./amazon-eks-ami-main/ ./amazon-eks-ami/ | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "new_git_changes=yes" >> $GITHUB_ENV | |
else | |
echo "new_git_changes=no" >> $GITHUB_ENV | |
fi | |
- name: Commit changes | |
run: | | |
if [ ${{ env.new_git_changes }} == 'yes' ]; then | |
git add . | |
git commit -am "Auto commit - CI build" | |
git push | |
fi | |
- name: Create a Github PR | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
if [ ${{ env.new_git_changes }} == 'yes' ]; then | |
gh pr create --title "New AMI version for EKS - Auto-PR" --body "New version, EKS AMI releases on <https://github.com/awslabs/amazon-eks-ami/releases/>" | |
else | |
echo "######## No Changes! ##############################" | |
fi | |