Add support for cleaning up the test server
# Conflicts: # README.md
This commit is contained in:
parent
062b82eb13
commit
7032e072fc
38
README.md
38
README.md
@ -11,12 +11,36 @@ This action takes the current branch (that triggered the workflow) and clones it
|
|||||||
> Please read the section [about the Compose file](#compose-file-1)
|
> Please read the section [about the Compose file](#compose-file-1)
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
```yaml
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- reopened
|
||||||
|
- synchronize
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.dsv.su.se/ansv7779/action-branch-deploy@v1
|
||||||
|
with:
|
||||||
|
ssh-key: ${{ secrets.BRANCH_DEPLOY_KEY }}
|
||||||
|
compose-file: compose.yaml
|
||||||
|
mode: 'deploy'
|
||||||
```
|
```
|
||||||
[...]
|
|
||||||
- uses: https://gitea.dsv.su.se/ansv7779/action-branch-deploy@v1
|
```yaml
|
||||||
with:
|
on:
|
||||||
ssh-key: ${{ secrets.BRANCH_DEPLOY_KEY }}
|
pull_request:
|
||||||
compose-file: compose.yaml
|
types:
|
||||||
|
- closed
|
||||||
|
jobs:
|
||||||
|
cleanup:
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.dsv.su.se/ansv7779/action-branch-deploy@v1
|
||||||
|
with:
|
||||||
|
cleanup-ssh-key: ${{ secrets.BRANCH_CLEANUP_KEY }}
|
||||||
|
compose-file: compose.yaml
|
||||||
|
mode: 'cleanup'
|
||||||
```
|
```
|
||||||
|
|
||||||
## TLDR
|
## TLDR
|
||||||
@ -35,6 +59,10 @@ Defaults to `${{ secrets.GITEA_TOKEN }}` which is populated by Gitea automatical
|
|||||||
The SSH key used to access the deploy script on branch.dsv.su.se.
|
The SSH key used to access the deploy script on branch.dsv.su.se.
|
||||||
Defaults to `${{ secrets.BRANCH_DEPLOY_KEY }}` and is populated for you in the DMC organisation.
|
Defaults to `${{ secrets.BRANCH_DEPLOY_KEY }}` and is populated for you in the DMC organisation.
|
||||||
|
|
||||||
|
### cleanup-ssh-key
|
||||||
|
The SSH key used to access the cleanup script on branch.dsv.su.se.
|
||||||
|
Defaults to `${{ secrets.BRANCH_CLEANUP_KEY }}` and is populated for you in the DMC organisation.
|
||||||
|
|
||||||
### compose-file
|
### compose-file
|
||||||
|
|
||||||
The Compose file to use when starting the services on branch.dsv.su.se.
|
The Compose file to use when starting the services on branch.dsv.su.se.
|
||||||
|
10
action.yml
10
action.yml
@ -2,9 +2,17 @@ name: 'Deploy to branch.dsv.su.se'
|
|||||||
description: 'Deploy the current branch via Docker Compose to branch.dsv.su.se'
|
description: 'Deploy the current branch via Docker Compose to branch.dsv.su.se'
|
||||||
inputs:
|
inputs:
|
||||||
ssh-key:
|
ssh-key:
|
||||||
description: 'The SSH key to use for authentication'
|
description: 'The SSH key to use for deploying'
|
||||||
default: ${{ secrets.BRANCH_DEPLOY_KEY }}
|
default: ${{ secrets.BRANCH_DEPLOY_KEY }}
|
||||||
required: true
|
required: true
|
||||||
|
cleanup-ssh-key:
|
||||||
|
description: 'The SSH key to use for cleanup'
|
||||||
|
default: ${{ secrets.BRANCH_CLEANUP_KEY }}
|
||||||
|
required: true
|
||||||
|
mode:
|
||||||
|
description: 'The mode to use, either deploy or cleanup'
|
||||||
|
default: 'deploy'
|
||||||
|
required: true
|
||||||
compose-file:
|
compose-file:
|
||||||
description: 'The Docker Compose file to use'
|
description: 'The Docker Compose file to use'
|
||||||
default: 'compose.yaml'
|
default: 'compose.yaml'
|
||||||
|
11
src/main.ts
11
src/main.ts
@ -3,6 +3,15 @@ import * as gitea from '@actions/github';
|
|||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
function getSSHKey() {
|
||||||
|
const mode = core.getInput('mode', {required: true});
|
||||||
|
if (mode === 'cleanup') {
|
||||||
|
return core.getInput('cleanup-ssh-key', {required: true});
|
||||||
|
} else {
|
||||||
|
return core.getInput('ssh-key', {required: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const branchName = process.env.GITHUB_HEAD_REF!;
|
const branchName = process.env.GITHUB_HEAD_REF!;
|
||||||
const repositoryName = gitea.context.repo.repo;
|
const repositoryName = gitea.context.repo.repo;
|
||||||
@ -16,7 +25,7 @@ async function main() {
|
|||||||
|
|
||||||
core.setOutput('url', `https://${repositoryName}-${mangledBranchName}.branch.dsv.su.se`);
|
core.setOutput('url', `https://${repositoryName}-${mangledBranchName}.branch.dsv.su.se`);
|
||||||
|
|
||||||
const sshKey = core.getInput('ssh-key', {required: true});
|
const sshKey = getSSHKey();
|
||||||
core.info(`sshKey: ${sshKey.length}`);
|
core.info(`sshKey: ${sshKey.length}`);
|
||||||
fs.writeFileSync('ssh_key', `${sshKey}\n`, {flag: 'w+', mode: "0600"});
|
fs.writeFileSync('ssh_key', `${sshKey}\n`, {flag: 'w+', mode: "0600"});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user