62 lines
1.8 KiB
YAML
62 lines
1.8 KiB
YAML
name: CI/CD Test
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
types:
|
|
- closed
|
|
|
|
jobs:
|
|
build-deploy:
|
|
runs-on: act_runner_base
|
|
if: ${{ 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.event.pull_request.merged == true && github.event.pull_request.base.ref == '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 [ -z "$GITEA_TOKEN" ]; then
|
|
echo "Missing secrets.RUNNER_TOKEN"
|
|
exit 1
|
|
fi
|
|
api_url="$GITEA_SERVER_URL/api/v1/repos/$GITEA_REPOSITORY/releases"
|
|
payload=$(cat <<EOF
|
|
{
|
|
"tag_name": "$RELEASE_TAG",
|
|
"name": "$RELEASE_TAG",
|
|
"target_commitish": "$RELEASE_TARGET",
|
|
"draft": false,
|
|
"prerelease": false
|
|
}
|
|
EOF
|
|
)
|
|
curl -sS -X POST "$api_url" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$payload"
|