🐛 fix(ci): correggi URL istanza, token e struttura YAML nei workflow condivisi

- Sostituito URL hardcoded con ${{ gitea.server_url }} (portabilità)
- Sostituito ${{ secrets.GITEA_TOKEN }} con ${{ gitea.token }} (token automatico)
- Aggiunto env SERVER_URL/REPOSITORY per evitare espressioni inline nei curl
- Fix dependency-check: rimosso BODY multi-riga (bug YAML run:|) → printf + /tmp/body.md
- Fix auto-release: changelog su /tmp/changelog.txt (evita collisione workspace)
- Fix branch-cleanup: encoding branch via variabile (sicurezza shell)
This commit is contained in:
LucaZanni
2026-03-26 07:01:34 +01:00
parent e5df154060
commit f1305498c1
3 changed files with 19 additions and 22 deletions
+6 -4
View File
@@ -24,21 +24,23 @@ jobs:
CHANGELOG=$(git log --pretty=format:"- %s (%h)" "${PREV_TAG}..${CURRENT_TAG}") CHANGELOG=$(git log --pretty=format:"- %s (%h)" "${PREV_TAG}..${CURRENT_TAG}")
fi fi
echo "$CHANGELOG" > changelog.txt echo "$CHANGELOG" > /tmp/changelog.txt
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
- name: Create release - name: Create release
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ gitea.token }}
SERVER_URL: ${{ gitea.server_url }}
REPOSITORY: ${{ gitea.repository }}
run: | run: |
CURRENT_TAG=${{ steps.changelog.outputs.current_tag }} CURRENT_TAG=${{ steps.changelog.outputs.current_tag }}
APP_NAME=$(jq -r '.name' package.json) APP_NAME=$(jq -r '.name' package.json)
CHANGELOG=$(cat changelog.txt) CHANGELOG=$(cat /tmp/changelog.txt)
curl -s -X POST \ curl -s -X POST \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
"https://gitea.pzetatouch.it/api/v1/repos/${{ gitea.repository }}/releases" \ "$SERVER_URL/api/v1/repos/$REPOSITORY/releases" \
-d "{ -d "{
\"tag_name\": \"$CURRENT_TAG\", \"tag_name\": \"$CURRENT_TAG\",
\"name\": \"$APP_NAME $CURRENT_TAG\", \"name\": \"$APP_NAME $CURRENT_TAG\",
+6 -2
View File
@@ -10,7 +10,9 @@ jobs:
steps: steps:
- name: Delete merged branch - name: Delete merged branch
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ gitea.token }}
SERVER_URL: ${{ gitea.server_url }}
REPOSITORY: ${{ gitea.repository }}
run: | run: |
BRANCH="${{ gitea.event.pull_request.head.ref }}" BRANCH="${{ gitea.event.pull_request.head.ref }}"
@@ -19,8 +21,10 @@ jobs:
exit 0 exit 0
fi fi
ENCODED_BRANCH=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$BRANCH")
curl -s -X DELETE \ curl -s -X DELETE \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
"https://gitea.pzetatouch.it/api/v1/repos/${{ gitea.repository }}/branches/$(python3 -c "import urllib.parse; print(urllib.parse.quote('$BRANCH', safe=''))")" "$SERVER_URL/api/v1/repos/$REPOSITORY/branches/$ENCODED_BRANCH"
echo "Branch eliminato: $BRANCH" echo "Branch eliminato: $BRANCH"
+7 -16
View File
@@ -53,7 +53,9 @@ jobs:
- name: Open issue if problems found - name: Open issue if problems found
if: steps.audit.outputs.vulnerabilities != '0' || steps.outdated.outputs.count != '0' if: steps.audit.outputs.vulnerabilities != '0' || steps.outdated.outputs.count != '0'
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ gitea.token }}
SERVER_URL: ${{ gitea.server_url }}
REPOSITORY: ${{ gitea.repository }}
run: | run: |
VULNS="${{ steps.audit.outputs.vulnerabilities }}" VULNS="${{ steps.audit.outputs.vulnerabilities }}"
OUTDATED="${{ steps.outdated.outputs.count }}" OUTDATED="${{ steps.outdated.outputs.count }}"
@@ -62,25 +64,14 @@ jobs:
VULN_LIST=$(jq -r '.vulnerabilities | to_entries[] | "- \(.key): \(.value.severity)"' audit.json 2>/dev/null | head -20 || echo "N/A") VULN_LIST=$(jq -r '.vulnerabilities | to_entries[] | "- \(.key): \(.value.severity)"' audit.json 2>/dev/null | head -20 || echo "N/A")
OUTDATED_LIST=$(jq -r 'to_entries[] | "- \(.key): \(.value.current) → \(.value.latest)"' outdated.json 2>/dev/null | head -20 || echo "N/A") OUTDATED_LIST=$(jq -r 'to_entries[] | "- \(.key): \(.value.current) → \(.value.latest)"' outdated.json 2>/dev/null | head -20 || echo "N/A")
BODY="## Dependency Check — $DATE printf '## Dependency Check — %s\n\n### Vulnerabilità (high/critical): %s\n\n```\n%s\n```\n\n### Pacchetti obsoleti: %s\n\n```\n%s\n```\n' \
"$DATE" "$VULNS" "$VULN_LIST" "$OUTDATED" "$OUTDATED_LIST" > /tmp/body.md
### Vulnerabilità (high/critical): $VULNS
\`\`\`
$VULN_LIST
\`\`\`
### Pacchetti obsoleti: $OUTDATED
\`\`\`
$OUTDATED_LIST
\`\`\`"
curl -s -X POST \ curl -s -X POST \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
"https://gitea.pzetatouch.it/api/v1/repos/${{ gitea.repository }}/issues" \ "$SERVER_URL/api/v1/repos/$REPOSITORY/issues" \
-d "{ -d "{
\"title\": \"[$DATE] Dipendenze: $VULNS vulnerabilità, $OUTDATED obsoleti\", \"title\": \"[$DATE] Dipendenze: $VULNS vulnerabilità, $OUTDATED obsoleti\",
\"body\": $(echo "$BODY" | jq -Rs .) \"body\": $(jq -Rs . /tmp/body.md)
}" }"