diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..72142f9 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,55 @@ +name: Deploy + +on: + push: + branches: + - production + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Remove old deployment + run: | + PREVIOUS_DEPLOYMENT_ID=$(gh api /repos/${{ github.repository }}/deployments | jq -r '.[0].id') + gh api --method DELETE /repos/${{ github.repository }}/deployments/${PREVIOUS_DEPLOYMENT_ID} || true + env: + GH_TOKEN: ${{ github.token }} + + - name: Create new deployment + run: | + gh api --method POST \ + -H "Accept: application/vnd.github+json" \ + /repos/${{ github.repository }}/deployments \ + -f "ref=production" + DEPLOYMENT_ID=$(gh api /repos/${{ github.repository }}/deployments | jq -r '.[0].id') + env: + DEPLOYMENT_ID: ${{ steps.create.outputs.DEPLOYMENT_ID }} + GH_TOKEN: ${{ github.token }} + + - name: Create new deployment status + run: | + gh api --method POST \ + -H "Accept: application/vnd.github+json" \ + /repos/${{ github.repository }}/deployments/${{ env.DEPLOYMENT_ID }}/statuses \ + -f "state=pending" \ + -f "auto_inactive=true" + env: + DEPLOYMENT_ID: ${{ steps.create.outputs.DEPLOYMENT_ID }} + GH_TOKEN: ${{ github.token }} + + - name: Fake deployment + run: | + sleep 10 + + - name: Update deployment status + run: | + gh api --method POST \ + -H "Accept: application/vnd.github+json" \ + /repos/${{ github.repository }}/deployments/${{ env.DEPLOYMENT_ID }}/statuses \ + -f "state=success" \ + -f "auto_inactive=true" + env: + DEPLOYMENT_ID: ${{ steps.create.outputs.DEPLOYMENT_ID }} + GH_TOKEN: ${{ github.token }}