217 lines
7.9 KiB
YAML
217 lines
7.9 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: Install tea
|
|
uses: supplypike/setup-bin@v4
|
|
with:
|
|
uri: 'https://gitea.com/gitea/tea/releases/download/v0.9.2/tea-0.9.2-linux-amd64'
|
|
name: 'tea'
|
|
version: '0.9.2'
|
|
|
|
- name: Check if PR exists & Create
|
|
id: list-prs
|
|
run: |
|
|
tea login add --name gitea-rinoa --url ${{ secrets.RINOA_GITEA_URL }} --user gitea-sonarqube-bot --password "${{ secrets.BOT_GITEA_PASSWORD }}" --token ${{ secrets.BOT_GITEA_TOKEN }}
|
|
tea login default gitea-rinoa
|
|
pr_state=$(tea pr ls --repo ${{ github.repository }} --state open --fields index,title,head,state --output csv | egrep ${{ gitea.ref_name }} | awk -F, '{print $4}' | sed -e 's|"||g')
|
|
if [ "${pr_state}" != open ]; then
|
|
tea pr c -r ${{ github.repository }} -t "Automated PR for ${{ github.ref_name }}" -d "Automated PR for ${{ github.ref_name }}"
|
|
elif [ "${pr_state}" = open ]; then
|
|
echo "PR already exists, skipping creation..."
|
|
fi
|
|
|
|
docker-compose-test:
|
|
name: Docker Compose Test
|
|
needs: [check-and-create-pr]
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
VAULT_ADDR: ${{ secrets.RINOA_VAULT_ADDR }}
|
|
VAULT_TOKEN: ${{ secrets.RINOA_VAULT_TOKEN }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install jq
|
|
uses: dcarbone/install-jq-action@v3.0.1
|
|
|
|
- name: Install Vault
|
|
uses: cpanato/vault-installer@main
|
|
with:
|
|
vault-release: '1.18.3'
|
|
|
|
- name: Generate .env file for linting
|
|
run: |
|
|
vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .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
|
|
|
|
cloudflare-dns-setup:
|
|
name: Cloudflare DNS Setup
|
|
needs: [docker-compose-test]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install jq
|
|
uses: dcarbone/install-jq-action@v3.0.1
|
|
|
|
- name: Install yq
|
|
uses: dcarbone/install-yq-action@v1
|
|
|
|
- name: Install flarectl
|
|
uses: supplypike/setup-bin@v4
|
|
with:
|
|
uri: 'https://github.com/cloudflare/cloudflare-go/releases/download/v0.113.0/flarectl_0.113.0_linux_amd64.tar.gz'
|
|
name: 'flarectl'
|
|
version: '0.113.0'
|
|
|
|
- name: Grab Subdomains from Docker Compose & Cloudflare
|
|
id: grab-subdomains
|
|
env:
|
|
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
|
|
CF_API_EMAIL: ${{ secrets.CF_API_EMAIL }}
|
|
run: |
|
|
echo "Grabbing subdomains from docker-compose.yml..."
|
|
yq '.services[].labels.swag_url' docker-compose.yml | egrep -v 'null' | sed -e 's|"||g' | awk -F'.' '{print $1}' | sort > compose_subdomains.txt
|
|
echo "Grabbing subdomains from Cloudflare..."
|
|
flarectl --json dns list --zone "trez.wtf" --type=CNAME --content "trez.wtf" | jq '.[].Name' | sed -e 's|"||g' | awk -F"." '{print $1}' | sort > cloudflare_subdomains.txt
|
|
|
|
- name: Compare Subdomains
|
|
id: compare-subdomains
|
|
uses: LouisBrunner/diff-action@v2.2.0
|
|
with:
|
|
old: compose_subdomains.txt
|
|
new: cloudflare_subdomains.txt
|
|
mode: addition
|
|
tolerance: mixed-better
|
|
output: domain_compare.txt
|
|
|
|
- name: Create Subdomains
|
|
if: steps.compare-subdomains.outputs.output != ''
|
|
continue-on-error: true
|
|
env:
|
|
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
|
|
CF_API_EMAIL: ${{ secrets.CF_API_EMAIL }}
|
|
run: |
|
|
cat domain_compare.txt | egrep '^-[a-z]' | sed -e 's|-||g' | while read -r subdomain; do
|
|
echo "Creating $subdomain.trez.wtf..."
|
|
flarectl dns create --zone "trez.wtf" --name "${subdomain}" --type=CNAME --content "trez.wtf"
|
|
done
|
|
|
|
regenerate-readme:
|
|
name: Update README
|
|
runs-on: ubuntu-latest
|
|
if: ${{ always() }}
|
|
needs: [cloudflare-dns-setup]
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install yq
|
|
uses: dcarbone/install-yq-action@v1
|
|
|
|
- name: Generate README list
|
|
id: readme-list
|
|
run: |
|
|
services_list=$(yq '.services | to_entries | map({"service": .key, "image": .value.image})' docker-compose.yml)
|
|
echo "SERVICES_LIST<<EOF" >> $GITHUB_ENV
|
|
echo "${services_list}" >> $GITHUB_ENV
|
|
echo "EOF" >> $GITHUB_ENV
|
|
|
|
- name: Regenerate README
|
|
uses: gnpaone/dynamic-update-readme@v1.0.2
|
|
with:
|
|
marker_text: "SERVICES_LIST"
|
|
markdown_text: |
|
|
```yaml
|
|
${{ env.SERVICES_LIST }}
|
|
````
|
|
commit_email: noreply@trez.wtf
|
|
commit_username: gitea-sonarqube-bot
|
|
commit_message: "docs: regenerate README"
|
|
|
|
deployment-trigger:
|
|
name: Deployment Trigger
|
|
if: ${{ always() }}
|
|
needs: [generate-readme]
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
CONTINUE_JOBS: ${{ steps.deploy-trigger.outputs.CONTINUE_JOBS }}
|
|
steps:
|
|
- name: Install tea
|
|
uses: supplypike/setup-bin@v4
|
|
with:
|
|
uri: 'https://gitea.com/gitea/tea/releases/download/v0.9.2/tea-0.9.2-linux-amd64'
|
|
name: 'tea'
|
|
version: '0.9.2'
|
|
|
|
- name: PR Merge
|
|
run: |
|
|
tea login add --name gitea-rinoa --url ${{ secrets.RINOA_GITEA_URL }} --user gitea-sonarqube-bot --password "${{ secrets.BOT_GITEA_PASSWORD }}" --token ${{ secrets.BOT_GITEA_TOKEN }}
|
|
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 of PR #${pr_index} - ${{ gitea.ref_name }}" --message "Merged by ${{ gitea.actor }}" --output table ${pr_index}
|
|
|
|
- name: Gotify Notification
|
|
uses: eikendev/gotify-action@master
|
|
with:
|
|
gotify_api_base: '${{ secrets.RINOA_GOTIFY_URL }}'
|
|
gotify_app_token: '${{ secrets.RINOA_GOTIFY_TOKEN }}'
|
|
notification_title: 'Ready to Deploy'
|
|
notification_message: 'Ready to deploy: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs/${{ github.job }}'
|
|
|
|
- name: Trigger Deployment
|
|
id: deploy-trigger
|
|
uses: benhamiltonpro/manual-trigger@v1
|
|
with:
|
|
RUN_NAME: "docker-compose-deploy"
|
|
|
|
docker-compose-deploy:
|
|
name: Merge and Deploy
|
|
if: ${{ needs.deployment-trigger.outputs.CONTINUE_JOB == 'manual-step' }}
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
VAULT_ADDR: ${{ secrets.RINOA_VAULT_ADDR }}
|
|
VAULT_TOKEN: ${{ secrets.RINOA_VAULT_TOKEN }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: main
|
|
|
|
- name: Install Vault
|
|
uses: cpanato/vault-installer@main
|
|
|
|
- name: Generate .env file for deployment
|
|
run: |
|
|
vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env
|
|
|
|
- name: Docker Compose Deployment
|
|
uses: Autom3/docker-deployment-action@3.0.1
|
|
with:
|
|
remote_docker_host: gitea-deploy@192.168.1.254
|
|
ssh_private_key: ${{ secrets.RINOA_GITEA_PRIVATE_SSH_KEY }}
|
|
ssh_public_key: ${{ secrets.RINOA_GITEA_PUBLIC_SSH_KEY }}
|
|
|