fix(ci): use head_ref for PR checkout instead of ref_name
- 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:
@@ -37,8 +37,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
run: |
|
run: |
|
||||||
git clone --depth 1 --branch ${{ gitea.ref_name }} https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
|
# For PRs, use head_ref (source branch), for push use ref_name
|
||||||
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 Format Check
|
- name: Terraform Format Check
|
||||||
id: fmt
|
id: fmt
|
||||||
@@ -92,8 +97,12 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
run: |
|
run: |
|
||||||
git clone --depth 1 --branch ${{ gitea.ref_name }} https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
|
if [ "${{ gitea.event_name }}" = "pull_request" ]; then
|
||||||
git checkout ${{ gitea.sha }}
|
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
|
- name: Terraform Init
|
||||||
run: terraform init -input=false
|
run: terraform init -input=false
|
||||||
@@ -113,14 +122,6 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
working-directory: ${{ env.TF_WORKING_DIR }}
|
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
|
- name: Plan Summary
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
@@ -137,8 +138,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Comment PR with Plan
|
- name: Comment PR with Plan
|
||||||
if: gitea.event_name == 'pull_request'
|
if: gitea.event_name == 'pull_request'
|
||||||
env:
|
|
||||||
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
|
|
||||||
run: |
|
run: |
|
||||||
PLAN_OUTPUT=$(cat plan_output.txt | head -c 60000)
|
PLAN_OUTPUT=$(cat plan_output.txt | head -c 60000)
|
||||||
COMMENT_BODY=$(cat <<EOF
|
COMMENT_BODY=$(cat <<EOF
|
||||||
@@ -184,7 +183,6 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
run: |
|
run: |
|
||||||
git clone --depth 1 --branch ${{ gitea.ref_name }} https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
|
git clone --depth 1 --branch ${{ gitea.ref_name }} https://${GIT_TOKEN}@gitea.arnodo.fr/${{ gitea.repository }}.git .
|
||||||
git checkout ${{ gitea.sha }}
|
|
||||||
|
|
||||||
- name: Terraform Init
|
- name: Terraform Init
|
||||||
run: terraform init -input=false
|
run: terraform init -input=false
|
||||||
|
|||||||
Reference in New Issue
Block a user