Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a00763d8f | |||
| 4a79ce9d17 | |||
| 9d402578bd | |||
| 63ce59e604 |
@@ -259,6 +259,47 @@ jobs:
|
|||||||
source /tmp/build-ctx/build.env
|
source /tmp/build-ctx/build.env
|
||||||
bash scripts/report-status.sh failure "Docker push $NEXT_VERSION FAILED" ci-docker-push
|
bash scripts/report-status.sh failure "Docker push $NEXT_VERSION FAILED" ci-docker-push
|
||||||
|
|
||||||
|
- name: Delete Docker image artifact from Gitea (Python)
|
||||||
|
if: always()
|
||||||
|
shell: python
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
SERVER_URL: ${{ gitea.server_url }}
|
||||||
|
REPOSITORY: ${{ gitea.repository }}
|
||||||
|
RUN_ID: ${{ gitea.run_id }}
|
||||||
|
ARTIFACT_NAME: "docker-image"
|
||||||
|
run: |
|
||||||
|
import os, urllib.request, json
|
||||||
|
|
||||||
|
token = os.environ['GITEA_TOKEN']
|
||||||
|
server = os.environ['SERVER_URL']
|
||||||
|
repo = os.environ['REPOSITORY']
|
||||||
|
run_id = os.environ['RUN_ID']
|
||||||
|
target_name = os.environ['ARTIFACT_NAME']
|
||||||
|
|
||||||
|
# 1. Haetaan listaus artifakteista
|
||||||
|
url = f"{server}/api/v1/repos/{repo}/actions/runs/{run_id}/artifacts"
|
||||||
|
req = urllib.request.Request(url, headers={"Authorization": f"token {token}"})
|
||||||
|
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req) as response:
|
||||||
|
data = json.loads(response.read().decode())
|
||||||
|
|
||||||
|
# 2. Etsitään oikea ID
|
||||||
|
artifacts = data.get("artifacts", [])
|
||||||
|
artifact_id = next((a["id"] for a in artifacts if a["name"] == target_name), None)
|
||||||
|
|
||||||
|
# 3. Jos löytyi, lähetetään DELETE-pyyntö
|
||||||
|
if artifact_id:
|
||||||
|
del_url = f"{server}/api/v1/repos/{repo}/actions/artifacts/{artifact_id}"
|
||||||
|
del_req = urllib.request.Request(del_url, headers={"Authorization": f"token {token}"}, method="DELETE")
|
||||||
|
with urllib.request.urlopen(del_req) as del_res:
|
||||||
|
print(f"Artifakti {target_name} (ID: {artifact_id}) poistettu onnistuneesti levyltä.")
|
||||||
|
else:
|
||||||
|
print(f"Artifaktia '{target_name}' ei löytynyt listalta. Se on jo poistettu.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Poisto ohitettiin virheen vuoksi (esim. puuttuvat oikeudet): {e}")
|
||||||
|
|
||||||
tag-commit:
|
tag-commit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [check, push]
|
needs: [check, push]
|
||||||
@@ -326,31 +367,3 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
source /tmp/build-ctx/build.env
|
source /tmp/build-ctx/build.env
|
||||||
bash scripts/report-status.sh failure "Tag $NEXT_VERSION FAILED" ci-docker-tag
|
bash scripts/report-status.sh failure "Tag $NEXT_VERSION FAILED" ci-docker-tag
|
||||||
|
|
||||||
cleanup:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [tag-commit]
|
|
||||||
if: always()
|
|
||||||
steps:
|
|
||||||
- name: Delete build artifacts
|
|
||||||
run: |
|
|
||||||
echo "Siivotaan artifactit..."
|
|
||||||
RUN_ID="${{ github.run_id }}"
|
|
||||||
REPO="${{ github.repository }}"
|
|
||||||
SERVER="${{ gitea.server_url }}"
|
|
||||||
|
|
||||||
# List artifacts for this run
|
|
||||||
ARTIFACTS=$(curl -s \
|
|
||||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
||||||
"${SERVER}/api/v1/repos/${REPO}/actions/runs/${RUN_ID}/artifacts")
|
|
||||||
|
|
||||||
echo "Artifacts: $(echo "$ARTIFACTS" | jq -r '.artifacts | length') kpl"
|
|
||||||
|
|
||||||
# Delete each by name
|
|
||||||
echo "$ARTIFACTS" | jq -r '.artifacts[] | .name' | while IFS= read -r name; do
|
|
||||||
echo "Deleting: $name"
|
|
||||||
curl -s -X DELETE \
|
|
||||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
||||||
"${SERVER}/api/v1/repos/${REPO}/actions/runs/${RUN_ID}/artifacts/${name}"
|
|
||||||
echo " -> deleted $name"
|
|
||||||
done
|
|
||||||
|
|||||||
Reference in New Issue
Block a user