diff --git a/README.md b/README.md index 3631c62..7eef03c 100644 --- a/README.md +++ b/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) ## 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. diff --git a/action.yml b/action.yml index f11f3c5..c18bbdd 100644 --- a/action.yml +++ b/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' 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' diff --git a/src/main.ts b/src/main.ts index 549c23d..998b7a2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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"});