|
name: do-the-job |
|
on: |
|
push: |
|
branches: |
|
- master |
|
|
|
workflow_dispatch: |
|
|
|
jobs: |
|
start-runner: |
|
name: Start self-hosted EC2 runner |
|
runs-on: ubuntu-latest |
|
outputs: |
|
label: ${{ steps.start-ec2-runner.outputs.label }} |
|
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }} |
|
steps: |
|
- name: Configure AWS credentials |
|
uses: aws-actions/configure-aws-credentials@v4 |
|
with: |
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
|
aws-region: ${{ secrets.AWS_REGION }} |
|
- name: Start EC2 runner |
|
id: start-ec2-runner |
|
uses: machulav/ec2-github-runner@v2 |
|
with: |
|
mode: start |
|
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} |
|
ec2-image-id: ami-044b0717aadbc9dfa |
|
ec2-instance-type: t2.xlarge |
|
subnet-id: subnet-024811dee81325f1c |
|
security-group-id: sg-0646c2a337a355a31 |
|
|
|
do-the-job: |
|
name: Do the job on the runner |
|
needs: start-runner |
|
runs-on: ${{ needs.start-runner.outputs.label }} |
|
steps: |
|
- name: Clone the repository |
|
uses: actions/checkout@v4 |
|
with: |
|
fetch-depth: 0 |
|
- name: Run custom command |
|
run: echo 'Hello World!' |
|
|
|
stop-runner: |
|
name: Stop self-hosted EC2 runner |
|
needs: |
|
- start-runner |
|
- do-the-job |
|
runs-on: ubuntu-latest |
|
if: ${{ always() }} |
|
steps: |
|
- name: Configure AWS credentials |
|
uses: aws-actions/configure-aws-credentials@v4 |
|
with: |
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
|
aws-region: ${{ secrets.AWS_REGION }} |
|
- name: Stop EC2 runner |
|
uses: machulav/ec2-github-runner@v2 |
|
with: |
|
mode: stop |
|
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} |
|
label: ${{ needs.start-runner.outputs.label }} |
|
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }} |
|
|