name: ci/cd
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]

jobs:
  Build:
    runs-on: all
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: Declare variables
        run: |
          echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
          echo "run_name=$(echo "$GITHUB_REPOSITORY" | sed "s/\//_/")" >> "$GITHUB_ENV"
          echo "domain_name="www.msweb.io"" >> "$GITHUB_ENV"
          echo "docker_port="80"" >> "$GITHUB_ENV"
      - name: Build docker
        run: |
          docker build -t ${{ gitea.repository }}:${{ env.sha_short }} -t ${{ gitea.repository }}:latest .
      - name: Start docker
        run: |
          docker container rm -f ${{ env.run_name }} || true
          docker run -d --network=web --restart unless-stopped --name ${{ env.run_name }} ${{ gitea.repository }}:${{ env.sha_short }}
          /usr/bin/caddyconf --add --url ${{ env.domain_name }} --name ${{ env.run_name }} --port ${{ env.docker_port }}




