adding config + pipeline #173
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: Push | |
on: | |
push: | |
branches: | |
- rule-sets-DTSPO-17918 | |
env: | |
TF_LOG: INFO | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
deploy-infra: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: 'Az CLI login' | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }} | |
- name: 'Run az commands' | |
run: | | |
az account show | |
- name: Install jq | |
run: | | |
sudo apt-get install jq -y | |
- name: List all Repositories and Branches from JSON file | |
run: | | |
echo "Checking Repositories and Branches" | |
cat ./test-repos.json | |
for repo in $(jq -r '.[]' ./test-repos.json); do | |
echo "Checking repository: $repo" | |
curl -H "Authorization: token ${{ secrets.PAT_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/hmcts/$repo | |
for branch in main master; do | |
echo "Checking branch: $branch in repository: $repo" | |
curl -H "Authorization: token ${{ secrets.PAT_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/hmcts/$repo/branches/$branch | |
done | |
done | |
- name: Terraform Init | |
working-directory: components | |
env: | |
STORAGE_ACCOUNT: ${{ secrets.STORAGE_ACCOUNT }} | |
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }} | |
RESOURCE_GROUP_NAME: ${{ secrets.RESOURCE_GROUP_NAME }} | |
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }} | |
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
run: terraform init -backend-config="storage_account_name=$STORAGE_ACCOUNT" -backend-config="container_name=$CONTAINER_NAME" -backend-config="resource_group_name=$RESOURCE_GROUP_NAME" | |
- name: Terraform Plan | |
working-directory: components | |
env: | |
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }} | |
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: terraform plan -var="github_token=${{ secrets.PAT_TOKEN }}" | |
- name: Terraform Apply | |
working-directory: components | |
env: | |
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }} | |
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: terraform apply -var="github_token=${{ secrets.PAT_TOKEN }}" -auto-approve |