Skip to content

Commit 946cacb

Browse files
committed
Support GitHub deployments
1 parent 3723a5e commit 946cacb

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
name: Tests
1515
runs-on: ubuntu-latest
1616

17+
permissions:
18+
deployments: write
19+
1720
steps:
1821
# cloning into "root" does not work when trying to call the action from itself
1922
# inspired by Microsoft: https://github.com/microsoft/action-python/blob/c8ec939994d7ed2ec77b7bbe59ed5f5b72fb5607/.github/workflows/test.yml#L21
@@ -38,6 +41,8 @@ jobs:
3841
uses: ./action
3942
with:
4043
compose-file: action/docker-compose.test.yml
44+
environment: "test"
45+
environment-url: "https://www.simplificator.com"
4146
secrets: |
4247
- name: secret
4348
value: ${{ secrets.SECRET }}

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
jobs:
1616
deploy:
1717
runs-on: "ubuntu-latest"
18+
permissions:
19+
deployments: write
20+
1821
steps:
1922
- name: Checkout code
2023
uses: actions/checkout@v4
@@ -35,6 +38,8 @@ jobs:
3538
uses: simplificator/deploy-action@main
3639
with:
3740
compose-file: docker-compose.yml
41+
environment: production
42+
environment-url: https://example.com
3843
stack-name: my-app
3944
ssh-user-at-host: [email protected]
4045
secrets: |
@@ -44,13 +49,15 @@ jobs:
4449
4550
## Inputs
4651
47-
| Name | Description |
48-
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
49-
| `compose-file` | Path to your docker compose definition inside the repository. |
50-
| `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. |
51-
| `stack-name` | Name of the Docker Stack that shoud be created on your server. |
52-
| `ssh-user-at-host` | User@host to connect to (e.g. `[email protected]`) |
53-
| `ssh-port` | SSH port to connect to. Defaults to 22 if not defined. |
52+
| Name | Description |
53+
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
54+
| `compose-file` | Path to your docker compose definition inside the repository. |
55+
| `environment` | The name of the environment for the deployment (optional). Used to create a GitHub deployment. |
56+
| `environment-url` | A URL to access your deployment (optional). Used to create a GitHub deployment. |
57+
| `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. |
58+
| `stack-name` | Name of the Docker Stack that shoud be created on your server. |
59+
| `ssh-user-at-host` | User@host to connect to (e.g. `[email protected]`) |
60+
| `ssh-port` | SSH port to connect to. Defaults to 22 if not defined. |
5461

5562
## License
5663

action.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ inputs:
1313
description: 'Path to the docker-compose file'
1414
required: true
1515

16+
environment:
17+
description: "The name of the environment for the deployment"
18+
required: false
19+
20+
environment-url:
21+
description: "A URL to access your deployment"
22+
required: false
23+
1624
secrets:
1725
description: "Docker secrets to create during the stack"
1826
required: false
@@ -33,6 +41,16 @@ inputs:
3341
runs:
3442
using: "composite"
3543
steps:
44+
- uses: chrnorm/deployment-action@v2
45+
name: Create GitHub deployment
46+
id: deployment
47+
with:
48+
token: "${{ github.token }}"
49+
environment-url: "${{ inputs.environment-url }}"
50+
environment: "${{ inputs.environment }}"
51+
initial-status: "in_progress"
52+
if: "${{ inputs.environment != '' && inputs.environment-url != '' }}"
53+
3654
- name: Check if system is available through SSH
3755
run: "ssh -o ConnectTimeout=5 -p ${{ inputs.ssh-port }} ${{ inputs.ssh-user-at-host }} exit"
3856
shell: bash
@@ -76,3 +94,21 @@ runs:
7694
docker system prune -af
7795
docker context remove --force target
7896
shell: bash
97+
98+
- name: Update deployment status (success)
99+
uses: chrnorm/deployment-status@v2
100+
with:
101+
token: "${{ github.token }}"
102+
environment-url: "${{ steps.deployment.outputs.environment_url }}"
103+
deployment-id: "${{ steps.deployment.outputs.deployment_id }}"
104+
state: "success"
105+
if: "${{ inputs.environment != '' && inputs.environment-url != '' && success() }}"
106+
107+
- name: Update deployment status (failed)
108+
uses: chrnorm/deployment-status@v2
109+
with:
110+
token: "${{ github.token }}"
111+
environment-url: "${{ steps.deployment.outputs.environment_url }}"
112+
deployment-id: "${{ steps.deployment.outputs.deployment_id }}"
113+
state: "failure"
114+
if: "${{ inputs.environment != '' && inputs.environment-url != '' && failure() }}"

0 commit comments

Comments
 (0)