diff --git a/.github/workflows/clean.yml b/.github/workflows/clean.yml new file mode 100644 index 0000000..5a7b9d8 --- /dev/null +++ b/.github/workflows/clean.yml @@ -0,0 +1,37 @@ +name: Branch Deleted +on: delete + +env: + TAG_NAME: ${{ github.event.ref }} + +jobs: + delete: + strategy: + fail-fast: false + matrix: + component: + - name: consul-backup-daemon + if: github.event.ref_type == 'branch' + runs-on: ubuntu-latest + steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${GITHUB_ACTOR} + password: ${{secrets.GITHUB_TOKEN}} + - name: Prepare Tag + run: echo "TAG_NAME=$(echo ${TAG_NAME} | sed 's@refs/heads/@@;s@/@_@g')" >> $GITHUB_ENV + - name: Get package IDs for delete + id: get-ids-for-delete + uses: Netcracker/get-package-ids@v0.0.1 + with: + component-name: ${{ matrix.component.name }} + component-tag: ${{ env.TAG_NAME }} + access-token: ${{ secrets.GH_ACCESS_TOKEN }} + - uses: actions/delete-package-versions@v5 + with: + package-name: ${{ matrix.component.name }} + package-type: 'container' + package-version-ids: ${{ steps.get-ids-for-delete.outputs.ids-for-delete }} + if: ${{ steps.get-ids-for-delete.outputs.ids-for-delete != '' }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b672d62..c55b596 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -6,7 +6,7 @@ on: branches: - 'main' env: - TAG_NAME: ${{ github.event.release.tag_name || (github.ref == 'refs/heads/main' && 'main') }} + TAG_NAME: ${{ github.event.release.tag_name || github.ref }} jobs: multiplatform_build: @@ -30,6 +30,15 @@ jobs: registry: ghcr.io username: ${GITHUB_ACTOR} password: ${{secrets.GITHUB_TOKEN}} + - name: Prepare Tag + run: echo "TAG_NAME=$(echo ${TAG_NAME} | sed 's@refs/tags/@@;s@refs/heads/@@;s@/@_@g')" >> $GITHUB_ENV + - name: Get package IDs for delete + id: get-ids-for-delete + uses: Netcracker/get-package-ids@v0.0.1 + with: + component-name: ${{ matrix.component.name }} + component-tag: ${{ env.TAG_NAME }} + access-token: ${{ secrets.GH_ACCESS_TOKEN }} - name: Build and push uses: docker/build-push-action@v5 with: @@ -40,3 +49,9 @@ jobs: push: true tags: ghcr.io/netcracker/${{ matrix.component.name }}:${{ env.TAG_NAME }} provenance: false + - uses: actions/delete-package-versions@v5 + with: + package-name: ${{ matrix.component.name }} + package-type: 'container' + package-version-ids: ${{ steps.get-ids-for-delete.outputs.ids-for-delete }} + if: ${{ steps.get-ids-for-delete.outputs.ids-for-delete != '' }} \ No newline at end of file