Skip to content

Update aws/aws-sam-cli with latest commit hash from aws/aws-sam-cli-app-templates #4583

Update aws/aws-sam-cli with latest commit hash from aws/aws-sam-cli-app-templates

Update aws/aws-sam-cli with latest commit hash from aws/aws-sam-cli-app-templates #4583

name: Update aws/aws-sam-cli with latest commit hash from aws/aws-sam-cli-app-templates
on:
schedule:
- cron: "0 0/4 * * *" # run at the top of every 4 hour
workflow_dispatch: {}
jobs:
updateCommitHash:
permissions:
pull-requests: write
contents: write
if: github.repository == 'aws/aws-sam-cli'
runs-on: ubuntu-latest
steps:
- name: Checkout App Templates
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
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." --label "pr/internal"