Start VM #1250
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Register IP | |
| on: | |
| issues: | |
| types: [edited, labeled] | |
| jobs: | |
| forward: | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.issue.state == 'open' && | |
| contains(github.event.issue.labels.*.name, 'vm-ip') | |
| 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) | |
| ip_m = re.search(r'### Your public IP address\s*\n+([^\n#]+)', body) | |
| ok = True | |
| if not alias_m: | |
| print("::error::Could not find alias in issue body."); ok = False | |
| if not ip_m: | |
| print("::error::Could not find IP address in issue body."); ok = False | |
| if not ok: | |
| sys.exit(1) | |
| alias = alias_m.group(1).strip() | |
| ip = ip_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) | |
| if not re.fullmatch(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip): | |
| print(f"::error::'{ip}' is not a valid IPv4 address.") | |
| sys.exit(1) | |
| with open(os.environ["GITHUB_OUTPUT"], "a") as f: | |
| print(f"alias={alias}", file=f) | |
| print(f"ip_address={ip}", 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 IP address. Please make sure you used the issue template and that your IP is a valid IPv4 address (e.g. `203.0.113.42`). Run `curl -s ifconfig.me` to get your current public IP.' | |
| }); | |
| - name: Register IP | |
| id: dispatch | |
| env: | |
| GH_TOKEN: ${{ secrets.INFRA_DISPATCH_TOKEN }} | |
| ALIAS: ${{ steps.parse.outputs.alias }} | |
| IP_ADDRESS: ${{ steps.parse.outputs.ip_address }} | |
| run: | | |
| gh workflow run register-ip.yml \ | |
| --repo lewagon/terraform \ | |
| -f alias="$ALIAS" \ | |
| -f ip_address="$IP_ADDRESS" \ | |
| -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: '⏳ IP registration submitted. You will be notified once SSH access is enabled from your IP.' | |
| }); | |
| - 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.' | |
| }); |