fix(ci): use head_ref for PR checkout instead of ref_name
All checks were successful
Terraform CI/CD / Validate (push) Successful in 5s
Terraform CI/CD / Plan (push) Successful in 5s
Terraform CI/CD / Apply (push) Has been skipped

- gitea.ref_name returns PR number for pull_request events
- Use gitea.head_ref (source branch) for PRs
- Use gitea.ref_name for push events
- Remove unnecessary git checkout sha step
- Clean up redundant Save Plan Output step

Refs #3
This commit is contained in:
2025-12-08 15:56:31 +00:00
parent bb39dfa29e
commit bf80e60d7f

View File

@@ -37,8 +37,13 @@ jobs:
steps:
- name: Checkout
run: |
git clone --depth 1 --branch ${{ gitea.ref_name }} https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
git checkout ${{ gitea.sha }}
# For PRs, use head_ref (source branch), for push use ref_name
if [ "${{ gitea.event_name }}" = "pull_request" ]; then
BRANCH="${{ gitea.head_ref }}"
else
BRANCH="${{ gitea.ref_name }}"
fi
git clone --depth 1 --branch "${BRANCH}" https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
- name: Terraform Format Check
id: fmt
@@ -92,8 +97,12 @@ jobs:
steps:
- name: Checkout
run: |
git clone --depth 1 --branch ${{ gitea.ref_name }} https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
git checkout ${{ gitea.sha }}
if [ "${{ gitea.event_name }}" = "pull_request" ]; then
BRANCH="${{ gitea.head_ref }}"
else
BRANCH="${{ gitea.ref_name }}"
fi
git clone --depth 1 --branch "${BRANCH}" https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
- name: Terraform Init
run: terraform init -input=false
@@ -113,14 +122,6 @@ jobs:
exit 0
working-directory: ${{ env.TF_WORKING_DIR }}
- name: Save Plan Output
if: always()
run: |
mkdir -p /tmp/tfplan-artifact
cp tfplan /tmp/tfplan-artifact/ 2>/dev/null || true
cp plan_output.txt /tmp/tfplan-artifact/ 2>/dev/null || true
working-directory: ${{ env.TF_WORKING_DIR }}
- name: Plan Summary
if: always()
run: |
@@ -137,8 +138,6 @@ jobs:
- name: Comment PR with Plan
if: gitea.event_name == 'pull_request'
env:
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
PLAN_OUTPUT=$(cat plan_output.txt | head -c 60000)
COMMENT_BODY=$(cat <<EOF
@@ -184,7 +183,6 @@ jobs:
- name: Checkout
run: |
git clone --depth 1 --branch ${{ gitea.ref_name }} https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
git checkout ${{ gitea.sha }}
- name: Terraform Init
run: terraform init -input=false