Skip to content

Commit

Permalink
Support GitHub deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Mar 27, 2024
1 parent 3723a5e commit adc003a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
name: Tests
runs-on: ubuntu-latest

permissions:
deployments: write

steps:
# cloning into "root" does not work when trying to call the action from itself
# inspired by Microsoft: https://github.com/microsoft/action-python/blob/c8ec939994d7ed2ec77b7bbe59ed5f5b72fb5607/.github/workflows/test.yml#L21
Expand All @@ -38,6 +41,8 @@ jobs:
uses: ./action
with:
compose-file: action/docker-compose.test.yml
environment: "test"
environment-url: "https://www.simplificator.com"
secrets: |
- name: secret
value: ${{ secrets.SECRET }}
Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
jobs:
deploy:
runs-on: "ubuntu-latest"
permissions:
deployments: write

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -35,6 +38,8 @@ jobs:
uses: simplificator/deploy-action@main
with:
compose-file: docker-compose.yml
environment: production
environment-url: https://example.com
stack-name: my-app
ssh-user-at-host: [email protected]
secrets: |
Expand All @@ -44,13 +49,15 @@ jobs:
## Inputs
| Name | Description |
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `compose-file` | Path to your docker compose definition inside the repository. |
| `secrets` | Allows to define a YAML array of Docker secrets which should be created (not required). You need to define it as a multiline YAML string, as this is technically not supported by Actions directly. |
| `stack-name` | Name of the Docker Stack that shoud be created on your server. |
| `ssh-user-at-host` | User@host to connect to (e.g. `[email protected]`) |
| `ssh-port` | SSH port to connect to. Defaults to 22 if not defined. |
| Name | Description |
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `compose-file` | Path to your docker compose definition inside the repository. |
| `environment` | The name of the environment for the deployment (optional). Used to create a GitHub deployment. |
| `environment-url` | A URL to access your deployment (optional). Used to create a GitHub deployment. |
| `secrets` | Allows to define a YAML array of Docker secrets which should be created (optional). You need to define it as a multiline YAML string, as this is technically not supported by Actions directly. |
| `stack-name` | Name of the Docker Stack that shoud be created on your server. |
| `ssh-user-at-host` | User@host to connect to (e.g. `[email protected]`) |
| `ssh-port` | SSH port to connect to. Defaults to 22 if not defined. |

## License

Expand Down
36 changes: 36 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ inputs:
description: 'Path to the docker-compose file'
required: true

environment:
description: "The name of the environment for the deployment"
required: false

environment-url:
description: "A URL to access your deployment"
required: false

secrets:
description: "Docker secrets to create during the stack"
required: false
Expand All @@ -33,6 +41,16 @@ inputs:
runs:
using: "composite"
steps:
- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
environment-url: "${{ inputs.environment-url }}"
environment: "${{ inputs.environment }}"
initial-state: "in_progress"
if: "${{ inputs.environment != '' && inputs.environment-url != '' }}"

- name: Check if system is available through SSH
run: "ssh -o ConnectTimeout=5 -p ${{ inputs.ssh-port }} ${{ inputs.ssh-user-at-host }} exit"
shell: bash
Expand Down Expand Up @@ -76,3 +94,21 @@ runs:
docker system prune -af
docker context remove --force target
shell: bash

- name: Update deployment status (success)
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
environment-url: "${{ steps.deployment.outputs.environment_url }}"
deployment-id: "${{ steps.deployment.outputs.deployment_id }}"
state: "success"
if: "${{ inputs.environment != '' && inputs.environment-url != '' && success() }}"

- name: Update deployment status (failed)
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
environment-url: "${{ steps.deployment.outputs.environment_url }}"
deployment-id: "${{ steps.deployment.outputs.deployment_id }}"
state: "failure"
if: "${{ inputs.environment != '' && inputs.environment-url != '' && failure() }}"

0 comments on commit adc003a

Please sign in to comment.