Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add gh action to update app templates hash #3838

Merged
merged 8 commits into from
Apr 26, 2022
51 changes: 51 additions & 0 deletions .github/workflows/update_app_templates_hash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Update aws/aws-sam-cli with latest commit hash from aws/aws-sam-cli-app-templates

on:
schedule:
- cron: "0 * * * *" # run at the top of every hour
workflow_dispatch: {}

jobs:
updateCommitHash:
permissions:
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout App Templates
mndeveci marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/checkout@v3
with:
repository: aws/aws-sam-cli-app-templates
path: aws-sam-cli-app-templates

- name: Checkout SAM CLI
uses: actions/checkout@v3
with:
repository: aws/aws-sam-cli
path: aws-sam-cli

- name: Update hash & commit
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
cd aws-sam-cli-app-templates
APP_TEMPLATES_COMMIT_HASH=$(git rev-parse HEAD)
cd ../aws-sam-cli
git checkout -b update_app_templates_hash
git reset --hard develop
cat <<< "$(jq --arg commit_hash "$APP_TEMPLATES_COMMIT_HASH" --indent 4 '.app_template_repo_commit = $commit_hash' samcli/runtime_config.json)" > samcli/runtime_config.json
git status
git diff --quiet && exit 0 # exit if there is no change
echo "is_hash_changed=1" >> $GITHUB_ENV # set env variable for next step run decision
git add -u
git commit -m "feat: updating app templates repo hash with ($APP_TEMPLATES_COMMIT_HASH)"

- name: Raise PR for SAM CLI
mndeveci marked this conversation as resolved.
Show resolved Hide resolved
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ env.is_hash_changed == 1 }} # run only if there was a change
run: |
cd aws-sam-cli
git push --force origin update_app_templates_hash
gh pr list --repo aws/aws-sam-cli --head update_app_templates_hash --json id --jq length | grep 1 && exit 0 # exit if there is existing pr
gh pr create --base develop --head update_app_templates_hash --title "feat: update SAM CLI with latest App Templates commit hash" --body "This PR & commit is automatically created from App Templates repo to update the SAM CLI with latest hash of the App Templates."