Skip to content

use env_name instead of environment, cluster_tags instead of tags #4

use env_name instead of environment, cluster_tags instead of tags

use env_name instead of environment, cluster_tags instead of tags #4

Workflow file for this run

name: Initialize Repository
on:
# Run on pull requests that involve the repo-init branch
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- master
# Keep the manual trigger option as well for flexibility
workflow_dispatch:
inputs:
config_path:
description: 'Path to config.json file'
required: false
default: 'config.json'
type: string
jobs:
initialize:
name: Initialize Repository from Template
# Only run if the head branch is repo-init
if: github.head_ref == 'repo-init' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history and tags
ref: ${{ github.head_ref || 'repo-init' }} # Explicitly checkout repo-init branch
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Setup locale environment
run: |
echo "Setting up locale environment..."
sudo apt-get update
sudo apt-get install -y locales
sudo locale-gen en_US.UTF-8
echo "LC_ALL=en_US.UTF-8" >> $GITHUB_ENV
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
echo "LANGUAGE=en_US.UTF-8" >> $GITHUB_ENV
- name: Configure pip
uses: CSVD/pip-config@main
- name: Install Ansible
run: |
python -m pip install --upgrade pip
pip install ansible
- name: Install dependencies
run: |
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
- name: Determine config path
id: config
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
CONFIG_PATH="${{ github.event.inputs.config_path }}"
else
CONFIG_PATH="config.json"
fi
# Create absolute path to config file if needed
if [[ "$CONFIG_PATH" != /* ]]; then
CONFIG_PATH="${{ github.workspace }}/${CONFIG_PATH}"
fi
echo "CONFIG_PATH=${CONFIG_PATH}" >> $GITHUB_ENV
echo "Using config file: ${CONFIG_PATH}"
- name: Verify config.json exists
run: |
if [ ! -f "${{ env.CONFIG_PATH }}" ]; then
echo "Error: Config file '${{ env.CONFIG_PATH }}' not found!"
exit 1
fi
cat "${{ env.CONFIG_PATH }}"
- name: Run Ansible Playbook
env:
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
run: |
ansible-playbook ansible/generate_hcl_files.yml -e "config_file=${{ env.CONFIG_PATH }}"
- name: Commit Changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
# Only commit if there are changes
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Initialize repository structure from template"
# Explicitly push to repo-init branch
git push origin HEAD:repo-init
fi