Skip to content

CI-cleanup-artifacts #756

CI-cleanup-artifacts

CI-cleanup-artifacts #756

name: 'CI-cleanup-artifacts'
on:
workflow_run:
types:
- completed
workflows: [CI-pr, CI-push]
jobs:
on-success:
runs-on: ubuntu-latest
name: Cleanup artifact
steps:
- name: Login
run: |
export GH_CONFIG_DIR=$PWD/.config
echo "GH_CONFIG_DIR=$GH_CONFIG_DIR" >> $GITHUB_ENV
mkdir $GH_CONFIG_DIR
echo "${{ secrets.KIIROTORI_GH_CONFIG_HOSTS }}" > $GH_CONFIG_DIR/hosts.yml
echo "${{ secrets.KIIROTORI_GH_CONFIG_CONFIG }}" > $GH_CONFIG_DIR/config.yml
- name: Get ID
run: |
echo "ARTIFACT_ID=$(gh api -H 'Accept: application/vnd.github+json' ${{ github.event.workflow_run.artifacts_url }} --jq .artifacts[].id)" >> $GITHUB_ENV
- name: Cleanup
if: env.ARTIFACT_ID != ''
run: |
gh api --method DELETE -H 'Accept: application/vnd.github+json' ${{ env.ENDPOINT }}
env:
ENDPOINT: /repos/${{ github.repository }}/actions/artifacts/${{ env.ARTIFACT_ID }}
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo 'The triggering workflow failed'