Files
rinoa-docker/.gitea/workflows/deployment.yml
T
2024-12-31 20:15:31 -05:00

135 lines
5.1 KiB
YAML

name: Gitea Branch PR, SonarQube Analyze, and Merge Workflow
on:
push:
branches-ignore:
- main
jobs:
# Job 1: Check if PR exists and create one if the branch is new
check-and-create-pr:
name: Check and Create PR
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: PR list
id: list-prs
run: |
pr_check=$(curl ${{ vars.RINOA_GITEA_URL }}/api/v1/repos/${{ github.repository }}/pulls/main/${{ github.ref_name }} \
-X 'GET' \
-H 'Accept: application/json' \
-H 'Authorization: token ${{ secrets.BOT_GITEA_TOKEN }}' \
-s | jq '{index: .number, state: .state}')
pr_state=$(echo ${pr_check} | jq -r '.state')
- name: Create PR
if: steps.list-prs.outputs.pr_state != 'open'
uses: arifer612/Gitea-PR-action@v1.2.0
with:
url: ${{ gitea.server_url }}
token: ${{ secrets.BOT_GITEA_TOKEN }}
assignee: ${{ gitea.actor }}
cloudflare-dns-setup:
name: Cloudflare DNS Setup
needs: [check-and-create-pr]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup yq
uses: dcarbone/install-yq-action@v1
- name: Setup go
uses: WillAbides/setup-go-faster@v1.14.0
with:
go-version: 'stable'
- name: Subdomain Check/Creation
id: domain-check
env:
CF_API_KEY: ${{ secrets.CF_API_TOKEN }}
CF_API_EMAIL: ${{ secrets.CF_API_EMAIL }}
run: |
if [ -z $(go env GOPATH) ]; then
export GOPATH=${{ github.workspace }}/go
if [ -z $(go env GOBIN) ]; then
export GOBIN=${{ github.workspace }}
echo "Installing flarectl..."
go install github.com/cloudflare/cloudflare-go/cmd/flarectl@latest > 2>&1
echo "Grabbing most up-to-date subdomain list from Cloudflare..."
./flarectl d l --zone trez.wtf --type CNAME --content trez.wtf | egrep -v 'ID' | awk '{print $5}' > cf_subdomain_list.txt
swag_urls=$(yq '.services[].labels.swag_url' docker-compose.yml | egrep -v 'null' | sed -e 's|"||g' | awk -F'.' '{print $1}')
for subdomain in $(echo ${swag_urls}); do
if grep -q ${subdomain} cf_subdomain_list.txt; then
echo "Subdomain ${subdomain}.trez.wtf already exists in Cloudflare. Skipping..."
else
echo "Subdomain ${subdomain}.trez.wtf does not exist in Cloudflare. Creating..."
flarectl d c --zone trez.wtf --name ${subdomain} --type CNAME --content trez.wtf --proxy
fi
done
# docker-compose-test:
# name: Docker Compose Test
# needs: [create-pr]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Generate ephemeral .env compose file
# id: generate-env-file-pr
# run: |
# echo "${{ secrets.RINOA_ENV }}" > .env
# - name: Docker Compose Lint
# uses: yu-ichiro/spin-up-docker-compose-action@v1
# with:
# file: docker-compose.yml
# pull: true
# pull-opts: --dry-run
# up: true
# up-opts: --dry-run -d --remove-orphans
# env:
# DOCKER_HOST: tcp://dockerproxy:2375
# merge-pr:
# name: PR Merge
# runs-on: ubuntu-latest
# needs: [docker-compose-test]
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Send Gotify Notification
# uses: eikendev/gotify-action@0.0.3
# with:
# gotify_api_base: '${{ secrets.GOTIFY_URL }}'
# gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}'
# notification_title: '${{ github.ref_name }} ready to be merged.'
# notification_message: '${{ gitea.server_url }}/issues'
# - name: Manual Approval
# uses: trstringer/manual-approval@v1
# with:
# secret: ${{ secrets.BOT_GITEA_TOKEN }}
# approvers: Trez.One
# minimum-approvals: 1
# issue-title: "Deployment of ${{ github.ref_name }}"
# issue-body: "Autobots, roll out!"
# exclude-workflow-initiator-as-approver: false
# additional-approved-words: ''
# additional-denied-words: ''
# - name: Tea CLI Setup & PR Merge
# run: |
# curl -sSL https://dl.gitea.com/tea/main/tea-main-linux-amd64 -o /usr/local/bin/tea
# chmod +x /usr/local/bin/tea
# echo "Merging PR..."
# tea login add --name gitea-rinoa --url ${{ vars.RINOA_GITEA_URL }} --user gitea-sonarqube-bot --password "${{ secrets.BOT_GITEA_PASSWORD }}" --token ${{ secrets.BOT_GITEA_TOKEN }}
# echo ${{ gitea.ref_name }}
# pr_index=$(tea pr ls --repo ${{ github.repository }} --state open --fields index,title,head,state --output csv | egrep ${{ gitea.ref_name }} | awk -F, '{print $1}' | sed -e 's|"||g')
# tea pr m --repo ${{ github.repository }} --title "Auto Merge" --message "Merged by ${{ gitea.actor }}" --output table ${pr_index}