Skip to content

Start VM

Start VM #1504

Workflow file for this run

name: Register key
on:
issues:
types: [edited, labeled]
jobs:
forward:
runs-on: ubuntu-latest
if: |
github.event.issue.state == 'open' &&
contains(github.event.issue.labels.*.name, 'ssh-key')
permissions:
issues: write
steps:
- name: Parse issue body
id: parse
env:
ISSUE_BODY: ${{ github.event.issue.body }}
run: |
python3 - <<'EOF'
import os, re, sys
body = os.environ["ISSUE_BODY"]
alias_m = re.search(r'### Your alias\s*\n+([^\n#]+)', body)
key_m = re.search(r'### Your SSH public key\s*\n+((ssh-rsa|ssh-ed25519|ecdsa-sha2-\S+)\s+\S+)', body)
ok = True
if not alias_m:
print("::error::Could not find alias in issue body."); ok = False
if not key_m:
print("::error::Could not find a valid SSH public key."); ok = False
if not ok:
sys.exit(1)
alias = alias_m.group(1).strip()
key = key_m.group(1).strip()
if not re.fullmatch(r'[a-z]+-[a-z]+-[0-9a-f]+', alias):
print(f"::error::Alias '{alias}' has an unexpected format (expected: word-word-hex).")
sys.exit(1)
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
print(f"alias={alias}", file=f)
print("ssh_key<<EOF_KEY", file=f)
print(key, file=f)
print("EOF_KEY", file=f)
EOF
- name: Parse error
if: failure() && steps.parse.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '❌ Could not read your alias or SSH key. Please make sure you used the issue template and that your public key starts with `ssh-ed25519`, `ssh-rsa`, or `ecdsa-sha2-...`.'
});
- name: Register key
id: dispatch
env:
GH_TOKEN: ${{ secrets.INFRA_DISPATCH_TOKEN }}
ALIAS: ${{ steps.parse.outputs.alias }}
SSH_KEY: ${{ steps.parse.outputs.ssh_key }}
run: |
gh workflow run register-key.yml \
--repo lewagon/terraform \
-f alias="$ALIAS" \
-f ssh_key="$SSH_KEY" \
-f github_username="${{ github.event.issue.user.login }}" \
-f issue_number="${{ github.event.issue.number }}" \
-f source_repo="${{ github.repository }}"
- name: Notify pending
if: success() && steps.dispatch.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '⏳ Your SSH key has been submitted. Key registration typically takes a few minutes. You will be notified once it is done.'
});
- name: Register error
if: failure() && steps.dispatch.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '⚠️ Error submitting data. Please contact the Le Wagon team.'
});