53 lines
1.7 KiB
YAML
53 lines
1.7 KiB
YAML
name: CI/CD Test
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
types:
|
|
- closed
|
|
|
|
jobs:
|
|
build-deploy:
|
|
runs-on: self-hosted
|
|
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.merged == true }}
|
|
steps:
|
|
- name: Set up environment
|
|
run: |
|
|
echo "PR #${{ github.event.number }} merged into master"
|
|
echo "Source branch: ${{ github.event.pull_request.head.ref }}"
|
|
echo "Target branch: ${{ github.event.pull_request.base.ref }}"
|
|
- name: Run tests
|
|
run: |
|
|
echo "Running test suite..."
|
|
- name: Build project
|
|
run: |
|
|
echo "Building project..."
|
|
- name: Deploy
|
|
if: success()
|
|
run: |
|
|
echo "Deploying to production..."
|
|
create-release:
|
|
runs-on: self-hosted
|
|
needs: build-deploy
|
|
if: ${{ success() && github.ref == 'refs/heads/master' }}
|
|
steps:
|
|
- name: Create release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.RUNNER_TOKEN }}
|
|
GITEA_SERVER_URL: ${{ github.server_url }}
|
|
GITEA_REPOSITORY: ${{ github.repository }}
|
|
RELEASE_TAG: ci-${{ github.run_id }}
|
|
RELEASE_TARGET: ${{ github.sha }}
|
|
run: |
|
|
if (-not $env:GITEA_TOKEN) { throw "Missing secrets.GITEA_TOKEN" }
|
|
$apiUrl = "$($env:GITEA_SERVER_URL)/api/v1/repos/$($env:GITEA_REPOSITORY)/releases"
|
|
$body = @{
|
|
tag_name = $env:RELEASE_TAG
|
|
name = $env:RELEASE_TAG
|
|
target_commitish = $env:RELEASE_TARGET
|
|
draft = $false
|
|
prerelease = $false
|
|
} | ConvertTo-Json
|
|
Invoke-RestMethod -Method Post -Uri $apiUrl -Headers @{ Authorization = "token $($env:GITEA_TOKEN)" } -Body $body -ContentType "application/json"
|