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 (Action) id: list-prs-action uses: andrea-armstrong/github-list-pull-requests@v1.0.0 with: token: ${{ secrets.BOT_GITEA_TOKEN }} state: all - name: PR list id: list-prs run: | pr_check=$(curl ${{ secrets.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 }}' \ -sS | jq '{index: .number, state: .state}') echo "PR List: ${pr_check}" pr_state=$(echo ${pr_check} | jq -r '.state') - name: Create PR if: steps.list-prs-action.outputs.pullRequestNumbers == '' uses: arifer612/Gitea-PR-action@v1.2.0 with: url: ${{ gitea.server_url }} token: ${{ secrets.BOT_GITEA_TOKEN }} pr-label: 'auto-deploy-pr' docker-compose-test: name: Docker Compose Test needs: [check-and-create-pr] runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Generate ephemeral .env compose file uses: Simporter/get-env-file-from-vault@v1.0.2 with: VAULT_ADDR: https://vault.trez.wtf VAULT_USERNAME: gitea VAULT_PASSWORD: ${{ secrets.VAULT_GITEA_PASSWORD }} VAULT_SECRETS_PATH: ${{ secrets.VAULT_SECRETS_PATH }} - 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 readme_list=$(yq '.services | to_entries | map({service: .key, image: .value.image})' docker-compose.yml) echo "readme_list=${readme_list}" >> $GITHUB_ENV - 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 != '' 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 merge-pr-regenerate-readme: name: PR Merge runs-on: ubuntu-latest if: ${{ always() }} needs: [cloudflare-dns-setup] steps: - name: Checkout uses: actions/checkout@v4 - run: echo ${{ env.readme_list }} # - name: Regenerate README # uses: VisualBean/reactive-readme@v1 # with: # value: ${{ env.readme_list }} # section: compose-services # branch: ${{ github.ref_name }} # token: ${{ secrets.BOT_GITEA_TOKEN }} # - name: Add/Commit/Push README.md # uses: mgrybyk-org/git-commit-pull-push-action@v1 # with: # add_args: README.md # repository: ${{ github.repository }} # branch: ${{ github.head_ref }} # commit_message: Regenerate README.md # - name: Install tea # uses: supplypike/setup-bin@v4 # with: # uri: https://dl.gitea.com/tea/main/tea-main-linux-amd64 # name: tea # version: main # - 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}