Delete a Repository #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Delete a Repository | |
on: | |
workflow_dispatch: | |
inputs: | |
port_payload: | |
required: true | |
description: "Port's payload, including details for who triggered the action and general context (blueprint, run id, etc...)" | |
type: string | |
secrets: | |
GH_ORG_TOKEN: | |
required: true | |
PORT_CLIENT_ID: | |
required: true | |
PORT_CLIENT_SECRET: | |
required: true | |
jobs: | |
backup: | |
name: Backup the Repository | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | |
- name: Compress current repository | |
id: compress | |
run: | | |
GITHUB_URL=${{ fromJson(inputs.port_payload).payload.entity.properties.url }} | |
ORG=$(echo "$GITHUB_URL" | cut -d'/' -f4) | |
REPO=$(echo "$GITHUB_URL" | cut -d'/' -f5) | |
ARCHIVE=backup-$ORG--$REPO-$(date +"%Y-%m-%d_%H-%M-%S").tar.gz | |
git clone $GITHUB_URL /tmp/repo | |
cd /tmp/repo | |
tar -czf /tmp/$ARCHIVE . | |
echo "::set-output name=ARCHIVE::$ARCHIVE" | |
- name: Upload repository archive as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ${{ steps.compress.outputs.ARCHIVE }} | |
path: /tmp/${{ steps.compress.outputs.ARCHIVE }} | |
retention-days: 60 | |
delete: | |
name: Delete the Repository | |
needs: backup | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Delete the repository | |
run: | | |
GITHUB_URL=${{ fromJson(inputs.port_payload).payload.entity.properties.url }} | |
ORG=$(echo "$GITHUB_URL" | cut -d'/' -f4) | |
REPO=$(echo "$GITHUB_URL" | cut -d'/' -f5) | |
curl -L \ | |
-X DELETE \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GH_ORG_TOKEN }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$ORG/$REPO | |
- uses: port-labs/port-github-action@v1 | |
name: Delete the entity from Port | |
with: | |
clientId: ${{ secrets.PORT_CLIENT_ID }} | |
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }} | |
operation: DELETE | |
identifier: ${{ fromJson(inputs.port_payload).context.entity }} | |
blueprint: repository |