mirror of https://github.com/docker/docs.git
ci: clean netlify when PR get closed or merged
Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
parent
802c071377
commit
22a6ee2479
|
|
@ -0,0 +1,8 @@
|
|||
FROM node:lts-alpine
|
||||
|
||||
RUN apk add --no-cache jq
|
||||
RUN npm i -g netlify-cli
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
name: netlify action
|
||||
description: handle the integration with netlify
|
||||
inputs:
|
||||
netlify_token:
|
||||
description: Access token for netlify
|
||||
required: true
|
||||
site_name:
|
||||
description: Site name on netlify
|
||||
required: true
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.netlify_token }}
|
||||
- ${{ inputs.site_name }}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -xe
|
||||
|
||||
function usage() {
|
||||
echo "Usage: <netlify_auth_token> <site_name>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function slug() {
|
||||
echo $1 | sed -E s/[^a-zA-Z0-9]+/-/g | sed -E s/^-+\|-+$//g | tr A-Z a-z
|
||||
}
|
||||
|
||||
function get_site_id() {
|
||||
netlify sites:list --json | jq --raw-output ".[] | select(.name==\"$1\") | .id"
|
||||
}
|
||||
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
export NETLIFY_AUTH_TOKEN=$1
|
||||
site_name=$2
|
||||
|
||||
|
||||
echo "searching site ${site_name}"
|
||||
|
||||
clean_site_name=$(slug $site_name)
|
||||
site_id=$(get_site_id $clean_site_name)
|
||||
|
||||
echo "deleting site"
|
||||
|
||||
netlify sites:delete --force "${site_id}"
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
name: remove published site from netlify
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
|
||||
jobs:
|
||||
remove-site-from-netlify:
|
||||
name: build
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'docker/docker.github.io'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
- name: delete from netlify
|
||||
uses: ./.github/actions/netlify-clean
|
||||
with:
|
||||
netlify_token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||
site_name: "${{ github.repository }}/${{ github.head_ref }}"
|
||||
Loading…
Reference in New Issue