Update Code Snippets #64
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: Update Code Snippets | |
on: | |
schedule: | |
- cron: '0 0 * * 0' # Runs every Sunday at midnight | |
pull_request: | |
branches: | |
- main | |
paths: | |
- 'python/**' | |
workflow_dispatch: | |
jobs: | |
update-snippets: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: python | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.x | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
- name: Execute terraform-collector.py | |
run: python3 terraform-collector.py | |
- name: Check for changes | |
id: git-diff | |
run: | | |
git diff --exit-code || echo "public/code has changed" | |
if git diff-index --quiet HEAD --; then | |
echo "changed=false" >> $GITHUB_OUTPUT | |
else | |
echo "changed=true" >> $GITHUB_OUTPUT | |
fi | |
- name: List changed files | |
id: list-changes | |
run: | | |
CHANGED_FILES=$(git diff --name-only HEAD | tr '\n' ' ') | |
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV | |
- name: Commit and push | |
if: steps.git-diff.outputs.changed == 'true' && github.event_name != 'pull_request' | |
run: | | |
git config user.name "GitHub Action Bot" | |
git config user.email "github.bot@onwardplatforms.com" | |
git checkout -b automated-code-snippet-update | |
git add -A | |
git commit -m "Automated update of code snippets" | |
git push --force --set-upstream origin automated-code-snippet-update | |
- name: Create pull request | |
if: github.event_name != 'pull_request' | |
run: | | |
# Check if a PR already exists | |
if ! gh pr list --base main --head automated-code-snippet-update > /dev/null 2>&1; then | |
# Create a new PR | |
gh pr create --base main --head automated-code-snippet-update --title "Automated update of code snippets" --body "${{ env.CHANGED_FILES }}" | |
fi | |
env: | |
GH_TOKEN: ${{ github.token }} |