Closes #18 Reviewed-on: phoenix/textsender-auth#22 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
129 lines
3.6 KiB
YAML
129 lines
3.6 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: |
|
|
echo "Initializing config"
|
|
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 }}'
|
|
|
|
echo "Creating local .gitconfig"
|
|
touch ~/.gitconfig
|
|
cat > ~/.gitconfig << "EOF"
|
|
[url "ssh://git@${{ secrets.GIT_HOST_ROOT }}"]
|
|
insteadOf = https://${{ secrets.GIT_HOST_ROOT }}
|
|
EOF
|
|
|
|
echo "Building binary"
|
|
make build
|
|
|
|
echo "Binary built"
|
|
file textsender-auth
|
|
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-24.04
|
|
services:
|
|
postgres:
|
|
image: postgres:18.0
|
|
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
|
|
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
|
run: |
|
|
echo "Parent directory"
|
|
echo `pwd`
|
|
|
|
echo "SECRET_KEY=$SECRET_KEY" >> .env
|
|
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
|
|
|
|
echo "Initializing config"
|
|
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 }}'
|
|
|
|
echo "Creating local .gitconfig"
|
|
touch ~/.gitconfig
|
|
cat > ~/.gitconfig << "EOF"
|
|
[url "ssh://git@${{ secrets.GIT_HOST_ROOT }}"]
|
|
insteadOf = https://${{ secrets.GIT_HOST_ROOT }}
|
|
EOF
|
|
|
|
go test -v ./...
|