Files
FOSSBilling/.github/workflows/ci.yml
T

220 lines
7.0 KiB
YAML

name: CI
permissions:
contents: read
on:
push:
pull_request:
branches: main
types: [opened, reopened, synchronize, labeled, unlabeled]
pull_request_target:
branches: main
types: [opened, reopened, synchronize]
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'pull_request' && (github.event.action == 'labeled' || github.event.action == 'unlabeled') && 'labels' || 'run' }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
merge-hold:
name: 'Check for Merge Hold'
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: 'Check merge-hold label'
run: |
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'merge-hold') }}" == 'true' ]]; then
echo "Pull request labeled 'merge-hold'"
echo "The pull request cannot be merged until the 'merge-hold' label is removed."
exit 1
fi
echo "Pull request not labeled 'merge-hold'"
echo "The pull request can be merged as no 'merge-hold' label is set."
labeler:
name: 'Pull Request Labeler'
permissions:
contents: read
pull-requests: write
if: ${{ github.event_name == 'pull_request_target' }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/labeler@f27b608878404679385c85cfa523b85ccb86e213 # v6
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
sync-labels: true
release-drafter:
name: 'Release Drafter'
permissions:
contents: write
pull-requests: read
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: release-drafter/release-drafter@c2e2804cc59f45f57076a99af580d0fedb697927 # v7
with:
config-name: release-drafter.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
spellcheck:
name: 'Spellcheck'
runs-on: ubuntu-latest
timeout-minutes: 10
if: &normal_ci ${{ (github.event_name == 'pull_request' && github.event.action != 'labeled' && github.event.action != 'unlabeled' && github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id) || github.event_name == 'push' }}
steps:
- &checkout_step
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: 'Perform Spellcheck'
uses: streetsidesoftware/cspell-action@de2a73e963e7443969755b648a1008f77033c5b2 # v8
with:
incremental_files_only: true
php-build-test:
name: 'PHP Build and Test (${{ matrix.php }})'
permissions:
actions: write
contents: read
needs: [ spellcheck ]
if: *normal_ci
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
matrix:
php: ['8.3', '8.4', '8.5']
fail-fast: true
steps:
- *checkout_step
- name: 'Set up Docker Buildx'
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
- name: 'Build Docker Test Image'
run: |
docker buildx build \
--target test \
--build-arg PHP_VERSION=${{ matrix.php }} \
--build-arg INSTALL_TRANSLATIONS=false \
--cache-from type=gha,scope=fossbilling-test-${{ matrix.php }} \
--cache-to type=gha,scope=fossbilling-test-${{ matrix.php }},mode=max \
--load \
--tag fossbilling:test-${{ matrix.php }} \
.
- name: 'PHPStan'
run: |
docker run --rm \
--env APP_ENV=test \
fossbilling:test-${{ matrix.php }} \
./src/vendor/bin/phpstan analyse --configuration phpstan.neon --memory-limit=512M
- name: 'PHPUnit'
run: |
docker run --rm \
--env APP_ENV=test \
fossbilling:test-${{ matrix.php }} \
./src/vendor/bin/phpunit --configuration phpunit.xml.dist
- name: 'Run Live Tests'
if: ${{ matrix.php == '8.5' }}
run: bash ./.github/scripts/run-docker-live-tests.sh fossbilling:test-${{ matrix.php }}
preview-build:
name: 'Create Preview Release'
permissions:
actions: write
contents: read
id-token: write
needs: [ php-build-test ]
if: *normal_ci
uses: ./.github/workflows/release-build.yml
with:
artifact-name: 'preview-build'
preview: true
upload-preview:
name: 'Upload Preview Release'
needs: [ preview-build ]
if: *normal_ci
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: 'Download Preview Release Archive'
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: preview-build
path: '/tmp'
- name: 'Extract Preview Release Archive'
run: |
mkdir ./src
tar -xf /tmp/build.tar -C ./src
- name: 'Create Downloadable Preview'
run: zip -qr ../FOSSBilling-preview.zip .
working-directory: ./src/
- name: 'Move Downloadable Preview for Upload'
run: |
mkdir ./dist
mv ./FOSSBilling-preview.zip ./dist
- name: 'Upload Downloadable Preview to S3'
if: ${{ github.ref == 'refs/heads/main' }}
uses: jakejarvis/s3-sync-action@7ed8b112447abb09f1da74f3466e4194fc7a6311 # master
with:
args: '--acl public-read --follow-symlinks'
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_S3_ENDPOINT: ${{ secrets.AWS_S3_ENDPOINT }}
AWS_REGION: 'auto'
SOURCE_DIR: './dist'
- name: 'Upload Downloadable Preview to GitHub'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
if-no-files-found: 'error'
name: 'FOSSBilling Preview'
path: './src/*'
retention-days: 14
deploy-preview-docker:
name: 'Build and Push Preview to Docker Hub'
permissions:
contents: read
id-token: write
needs: [ preview-build ]
if: ${{ github.ref == 'refs/heads/main' }}
uses: docker/github-builder/.github/workflows/build.yml@c2782c55efa56a01b9c30021db8f5ec3993228a3 # v1.8.0
secrets:
registry-auths: |
- registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
with:
output: image
push: true
platforms: linux/amd64,linux/arm64
cache: false
sbom: true
set-meta-labels: true
set-meta-annotations: true
meta-images: fossbilling/fossbilling
meta-flavor: |
latest=false
meta-tags: |
type=raw,value=preview
build-args: |
FOSSBILLING_VERSION=${{ github.sha }}
FOSSBILLING_VERSION_TRUNCATE=7
SENTRY_DSN=${{ vars.SENTRY_DSN }}