Skip to content

merge: branch 'main' into dev #39

merge: branch 'main' into dev

merge: branch 'main' into dev #39

Workflow file for this run

name: Deploy to Staging Environment
on:
workflow_call:
push:
branches:
- dev
permissions:
deployments: write
jobs:
deploy:
runs-on: ubuntu-latest
if: github.repository_owner == 'onesoft-sudo'
steps:
- name: Create Deployment
id: create_deployment
run: |
# Create a deployment
out=$(curl -fSsL -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/deployments \
-d '{"ref": "${{ github.sha }}", "environment": "Staging", "auto_merge": false, "required_contexts": [], "description": "Deploying new release"}');
if [ -z "$out" ]; then
echo "Invalid output"
exit 1;
fi;
id=$(echo $out | jq -r .id);
if [ -z "$id" ]; then
echo "Invalid ID"
exit 1;
fi;
echo "id=$id" >> $GITHUB_OUTPUT;
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Deployment Status to Pending
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses \
-d '{"state": "pending", "environment": "Staging"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
run: |
curl -fSsL -X POST \
-H 'Authorization: Bearer ${{ secrets.UPDATE_KEY }}' \
https://ci.sudobot.online/deploy-staging.php
- name: Set Deployment Status to Success
if: success()
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses \
-d '{"state": "success", "environment": "Staging"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Deployment Status to Failure
if: failure()
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses \
-d '{"state": "failure", "environment": "Staging"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}