Add support for cleaning up the test server

# Conflicts:
#	README.md
This commit is contained in:
Andreas Svanberg 2024-11-25 12:56:29 +01:00
parent 062b82eb13
commit 7032e072fc
3 changed files with 52 additions and 7 deletions

@ -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)
## 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
with:
ssh-key: ${{ secrets.BRANCH_DEPLOY_KEY }}
compose-file: compose.yaml
```yaml
on:
pull_request:
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
@ -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.
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
The Compose file to use when starting the services on branch.dsv.su.se.

@ -2,9 +2,17 @@ name: 'Deploy to branch.dsv.su.se'
description: 'Deploy the current branch via Docker Compose to branch.dsv.su.se'
inputs:
ssh-key:
description: 'The SSH key to use for authentication'
description: 'The SSH key to use for deploying'
default: ${{ secrets.BRANCH_DEPLOY_KEY }}
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:
description: 'The Docker Compose file to use'
default: 'compose.yaml'

@ -3,6 +3,15 @@ import * as gitea from '@actions/github';
import * as exec from '@actions/exec';
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() {
const branchName = process.env.GITHUB_HEAD_REF!;
const repositoryName = gitea.context.repo.repo;
@ -16,7 +25,7 @@ async function main() {
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}`);
fs.writeFileSync('ssh_key', `${sshKey}\n`, {flag: 'w+', mode: "0600"});