Compare commits
1 Commits
prod
...
issues/27-test
| Author | SHA1 | Date | |
|---|---|---|---|
| 84c579e01e |
+31
-25
@@ -1,6 +1,6 @@
|
|||||||
name: cabinet-ci-cd
|
name: cabinet-ci-cd
|
||||||
|
|
||||||
# CI/CD: только push git-тега (ручное тегирование на ветке prod|test|stage).
|
# Pre-deploy PHPUnit on test|stage. Prod — без автотестов.
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -13,23 +13,6 @@ env:
|
|||||||
IMAGE_DEPLOY: git.sova.local/sova/cabinet
|
IMAGE_DEPLOY: git.sova.local/sova/cabinet
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup PHP
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: '8.4'
|
|
||||||
extensions: pdo_pgsql, pdo_mysql, redis, intl, zip, gd
|
|
||||||
- name: Prepare CI environment
|
|
||||||
run: |
|
|
||||||
cp .env.ci .env.local
|
|
||||||
mkdir -p var
|
|
||||||
- run: composer install --prefer-dist --no-interaction
|
|
||||||
- run: composer phpunit || true
|
|
||||||
- run: composer audit || true
|
|
||||||
|
|
||||||
parse-tag:
|
parse-tag:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
@@ -45,8 +28,36 @@ jobs:
|
|||||||
echo "env=$(echo "$TAG" | sed -E 's/cabinet-v([0-9.]+)-([a-z]+)/\2/')" >> "$GITHUB_OUTPUT"
|
echo "env=$(echo "$TAG" | sed -E 's/cabinet-v([0-9.]+)-([a-z]+)/\2/')" >> "$GITHUB_OUTPUT"
|
||||||
echo "version=$(echo "$TAG" | sed -E 's/cabinet-v([0-9.]+).*/\1/')" >> "$GITHUB_OUTPUT"
|
echo "version=$(echo "$TAG" | sed -E 's/cabinet-v([0-9.]+).*/\1/')" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
test:
|
||||||
|
needs: [parse-tag]
|
||||||
|
if: needs.parse-tag.outputs.env != 'prod'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.4'
|
||||||
|
extensions: pdo_pgsql, pdo_mysql, redis, intl, zip, gd
|
||||||
|
- name: Prepare CI environment
|
||||||
|
run: |
|
||||||
|
cp .env.ci .env.local
|
||||||
|
mkdir -p var
|
||||||
|
- run: composer install --prefer-dist --no-interaction
|
||||||
|
- name: PHPUnit
|
||||||
|
run: composer phpunit
|
||||||
|
- run: composer audit || true
|
||||||
|
|
||||||
|
test-prod-skip:
|
||||||
|
needs: [parse-tag]
|
||||||
|
if: needs.parse-tag.outputs.env == 'prod'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo "Prod tag — automated tests skipped."
|
||||||
|
|
||||||
build-and-push:
|
build-and-push:
|
||||||
needs: [test, parse-tag]
|
needs: [parse-tag, test, test-prod-skip]
|
||||||
|
if: always() && (needs.test.result == 'success' || needs.test.result == 'skipped') && (needs.test-prod-skip.result == 'success' || needs.test-prod-skip.result == 'skipped')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -100,13 +111,8 @@ jobs:
|
|||||||
git add "apps/cabinet/values-${ENV}.yaml"
|
git add "apps/cabinet/values-${ENV}.yaml"
|
||||||
git diff --cached --quiet && { echo "No changes"; exit 0; }
|
git diff --cached --quiet && { echo "No changes"; exit 0; }
|
||||||
git commit -m "chore(cabinet): bump ${ENV} to ${TAG}"
|
git commit -m "chore(cabinet): bump ${ENV} to ${TAG}"
|
||||||
if git push origin "${ENV}"; then
|
if git push origin "${ENV}"; then exit 0; fi
|
||||||
echo "Push OK on attempt ${attempt}"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
echo "Push failed, retry ${attempt}/${MAX_RETRIES}..."
|
|
||||||
git reset --hard HEAD~1
|
git reset --hard HEAD~1
|
||||||
sleep $((attempt * 2))
|
sleep $((attempt * 2))
|
||||||
done
|
done
|
||||||
echo "Failed to push after ${MAX_RETRIES} attempts"
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user