Files
schedtxt_auth/.gitea/workflows/workflow.yaml
T
2025-11-01 16:34:51 -04:00

120 lines
3.2 KiB
YAML

name: Go
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-24.04 # You can change this to macos-latest or windows-latest if needed
steps:
- uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.25.3' # You can specify a specific version or 'stable'
- name: Build
run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
chmod 600 ~/.ssh/textsender_models_deploy_key
ssh-keyscan ${{ vars.MY_HOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/textsender_models_deploy_key
go env -w GOPRIVATE='${{ secrets.GIT_HOST_ROOT }}'
cat > ~/.gitconfig << "EOF"
[url "ssh://git@${{ secreats.GIT_HOST_ROOT }}"]
insteadOf = https://${{ secrets.GIT_HOST_ROOT }}
EOF
cat ~/.gitconfig
make build
test:
name: Test
runs-on: ubuntu-24.04
services:
postgres:
image: postgres:17.5
env:
POSTGRES_USER: ${{ secrets.DB_TEST_USER }}
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD }}
POSTGRES_DB: ${{ secrets.DB_TEST_NAME }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.25.3'
- name: Install PostgreSQL client
run: sudo apt update && sudo apt-get install -y postgresql-client
- name: Wait for PostgreSQL to be ready
run: |
for i in {1..30}; do
if pg_isready -h postgres -p 5432; then
echo "PostgreSQL is ready"
exit 0
fi
echo "Waiting for PostgreSQL... Attempt $i"
sleep 2
done
echo "PostgreSQL did not start in time"
exit 1
- name: Run tests
env:
DB_NAME: ${{ secrets.DB_TEST_NAME }}
DB_USER: ${{ secrets.DB_TEST_USER }}
DB_PASSWORD: ${{ secrets.DB_TEST_PASSWORD }}
DB_HOST: postgres
DB_PORT: 5432
DB_SSLMODE: disable
run: |
echo "Parent directory"
echo `pwd`
echo "DB_NAME=$DB_NAME" > .env
echo "DB_USER=$DB_USER" >> .env
echo "DB_PASSWORD=$DB_PASSWORD" >> .env
echo "DB_HOST=$DB_HOST" >> .env
echo "DB_PORT=$DB_PORT" >> .env
echo "DB_SSLMODE=$DB_SSLMODE" >> .env
go test -v ./...
# - name: Run gofmt (optional)
# Uncomment to check code formatting with gofmt
# run: |
# if [ -n "$(gofmt -l.)" ]; then
# echo "Go code is not formatted. Please run 'gofmt -w.' to fix it."
# exit 1
# fi
# - name: Run golint (optional)
# Uncomment to check code style with golint
# run: |
# if [ -n "$(golint./...)" ]; then
# echo "Go code has style issues. Please run 'golint./...' to see them."
# exit 1
# fi