From 46b17b5c040e41724013bc9e33ca5966ce1ff996 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Sat, 16 Jan 2021 20:25:58 -0500 Subject: [PATCH] Use GitHub actions (#989) --- {.travis => .github/scripts}/Formatting.xml | 0 .../scripts/build.sh | 78 +----- .../env.travis.php => .github/scripts/env.php | 0 {.travis => .github/scripts}/my.cnf | 0 .../scripts/phpunit.xml | 0 .github/scripts/version.sh | 36 +++ .github/workflows/build.yml | 251 ++++++++++++++++++ .travis.yml | 162 ----------- 8 files changed, 294 insertions(+), 233 deletions(-) rename {.travis => .github/scripts}/Formatting.xml (100%) rename .travis/deploy_script.sh => .github/scripts/build.sh (50%) mode change 100755 => 100644 rename .travis/env.travis.php => .github/scripts/env.php (100%) rename {.travis => .github/scripts}/my.cnf (100%) rename .travis/phpunit.travis.xml => .github/scripts/phpunit.xml (100%) create mode 100644 .github/scripts/version.sh create mode 100644 .github/workflows/build.yml delete mode 100644 .travis.yml diff --git a/.travis/Formatting.xml b/.github/scripts/Formatting.xml similarity index 100% rename from .travis/Formatting.xml rename to .github/scripts/Formatting.xml diff --git a/.travis/deploy_script.sh b/.github/scripts/build.sh old mode 100755 new mode 100644 similarity index 50% rename from .travis/deploy_script.sh rename to .github/scripts/build.sh index 96fb20b2..9f9b7f42 --- a/.travis/deploy_script.sh +++ b/.github/scripts/build.sh @@ -1,52 +1,12 @@ #!/usr/bin/env bash -if [ "$TRAVIS" != "true" ]; then - exit 0 -fi - -cd $TRAVIS_BUILD_DIR - -if test "$TRAVIS_TAG"; then - VERSION=$TRAVIS_TAG - - # Pass in the tag as the version to write out - php artisan phpvms:version --write --write-full-version "${VERSION}" - FULL_VERSION=$(php artisan phpvms:version) -else - echo "On branch $TRAVIS_BRANCH" - - if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_BRANCH" != "dev" ]; then - echo "Not on valid branch, exiting" - exit 0 - fi - - # Write the version out but place the branch ID in there - # This is only for the dev branch - BASE_VERSION=$(php artisan phpvms:version --base-only) - - # This now includes the pre-release version, so "-dev" by default - VERSION=${BASE_VERSION} - - # Don't pass in a version here, just write out the latest hash - php artisan phpvms:version --write "${VERSION}" - FULL_VERSION=$(php artisan phpvms:version) -fi - -FILE_NAME="phpvms-${VERSION}" -TAR_NAME="$FILE_NAME.tar.gz" -ZIP_NAME="$FILE_NAME.zip" - echo "Version: ${VERSION}" echo "Full Version: ${FULL_VERSION}" echo "Package name: ${TAR_NAME}" - -echo "===========================" +echo "Current directory: ${BASE_DIR}" echo "Cleaning files" -rm -rf vendor -composer install --no-dev --prefer-dist --no-interaction --verbose - # Leftover individual files to delete declare -a remove_files=( .git @@ -107,44 +67,20 @@ mkdir -p storage/framework/cache mkdir -p storage/framework/sessions mkdir -p storage/framework/views -# Regenerate the autoloader and classes -composer dump-autoload -make clean - cd /tmp -ls -al $TRAVIS_BUILD_DIR/../ -tar -czf $TAR_NAME -C $TRAVIS_BUILD_DIR . +ls -al $BASE_DIR/../ + +tar -czf $TAR_NAME -C $BASE_DIR . sha256sum $TAR_NAME >"$TAR_NAME.sha256" tar2zip $TAR_NAME sha256sum $ZIP_NAME >"$ZIP_NAME.sha256" ls -al /tmp -echo "Uploading to S3" -mkdir -p $TRAVIS_BUILD_DIR/build -cd $TRAVIS_BUILD_DIR/build +echo "Moving to dist" +mkdir -p $BASE_DIR/dist +cd $BASE_DIR/dist mv "/tmp/$TAR_NAME" "/tmp/$ZIP_NAME" "/tmp/$TAR_NAME.sha256" "/tmp/$ZIP_NAME.sha256" . -artifacts upload --target-paths "/" $ZIP_NAME $TAR_NAME $TRAVIS_BUILD_DIR/VERSION $TAR_NAME.sha256 $ZIP_NAME.sha256 -# Upload the version for a tagged release. Move to a version file in different -# tags. Within phpVMS, we have an option of which version to track in the admin -if test "$TRAVIS_TAG"; then - echo "Uploading release version file" - cp "$TRAVIS_BUILD_DIR/VERSION" release_version - artifacts upload --target-paths "/" release_version -else - echo "Uploading ${TRAVIS_BRANCH}_version file" - cp $TRAVIS_BUILD_DIR/VERSION ${TRAVIS_BRANCH}_version - artifacts upload --target-paths "/" ${TRAVIS_BRANCH}_version -fi - -#if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_BRANCH" != "dev" ]; then -# echo "Skipping Discord branch update broadcast" -#else - curl -X POST \ - --data "{\"content\": \"A new build is available at http://downloads.phpvms.net/$TAR_NAME (${FULL_VERSION})\"}" \ - -H "Content-Type: application/json" \ - $DISCORD_WEBHOOK_URL -#fi diff --git a/.travis/env.travis.php b/.github/scripts/env.php similarity index 100% rename from .travis/env.travis.php rename to .github/scripts/env.php diff --git a/.travis/my.cnf b/.github/scripts/my.cnf similarity index 100% rename from .travis/my.cnf rename to .github/scripts/my.cnf diff --git a/.travis/phpunit.travis.xml b/.github/scripts/phpunit.xml similarity index 100% rename from .travis/phpunit.travis.xml rename to .github/scripts/phpunit.xml diff --git a/.github/scripts/version.sh b/.github/scripts/version.sh new file mode 100644 index 00000000..b877103a --- /dev/null +++ b/.github/scripts/version.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +if test "$GIT_TAG_NAME"; then + export VERSION=$GIT_TAG_NAME + + # Pass in the tag as the version to write out + php artisan phpvms:version --write --write-full-version "${VERSION}" + export FULL_VERSION=$(php artisan phpvms:version) +else + export BRANCH=${GITHUB_REF##*/} + echo "On branch $BRANCH" + + # Write the version out but place the branch ID in there + # This is only for the dev branch + export BASE_VERSION=$(php artisan phpvms:version --base-only) + + # This now includes the pre-release version, so "-dev" by default + export VERSION=${BASE_VERSION} + + # Don't pass in a version here, just write out the latest hash + php artisan phpvms:version --write "${VERSION}" + export FULL_VERSION=$(php artisan phpvms:version) +fi + +export FILE_NAME="phpvms-${VERSION}" +export TAR_NAME="$FILE_NAME.tar.gz" +export ZIP_NAME="$FILE_NAME.zip" +export BASE_DIR=`pwd` + +# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files +echo "BRANCH=${BRANCH}" >> $GITHUB_ENV +echo "FILE_NAME=${FILE_NAME}" >> $GITHUB_ENV +echo "TAR_NAME=${TAR_NAME}" >> $GITHUB_ENV +echo "ZIP_NAME=${ZIP_NAME}" >> $GITHUB_ENV +echo "BASE_DIR=${BASE_DIR}" >> $GITHUB_ENV +echo "DISCORD_MSG=A new build is available at http://downloads.phpvms.net/$TAR_NAME (${FULL_VERSION})" >> $GITHUB_ENV \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..69fbb03a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,251 @@ +name: 'Build' +on: ['push', 'workflow_dispatch', 'release'] +jobs: + build: + runs-on: ubuntu-18.04 + strategy: + fail-fast: true + matrix: + php-versions: ['7.3', '7.4'] + name: PHP ${{ matrix.php-versions }} + env: + extensions: intl, pcov, mbstring + key: cache-v1 + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Configure Caching + - name: Setup cache environment + id: cache-env + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + + - name: Cache extensions + uses: actions/cache@v1 + with: + path: ${{ steps.cache-env.outputs.dir }} + key: ${{ steps.cache-env.outputs.key }} + restore-keys: ${{ steps.cache-env.outputs.key }} + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + # Configure PHP + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + ini-values: post_max_size=256M, short_open_tag=On + coverage: xdebug + tools: php-cs-fixer, phpunit + + - name: Shutdown Ubuntu MySQL + run: sudo service mysql stop + + - name: Install MariaDB + uses: getong/mariadb-action@v1.1 + with: + character set server: 'utf8' + collation server: 'utf8_general_ci' + mysql database: 'phpvms' + mysql root password: '' + mysql user: '' + mysql password: '' + + - name: Configure Environment + run: | + php --version + mysql --version + # Downgrade composer version to 1.x + composer self-update --1 + composer install --dev --no-interaction --verbose + cp .github/scripts/env.php env.php + cp .github/scripts/phpunit.xml phpunit.xml + php artisan database:create --reset + php artisan migrate:refresh --seed + + - name: Run Tests + run: | + vendor/bin/php-cs-fixer fix --config=.php_cs -v --dry-run --diff --using-cache=no + vendor/bin/phpunit --debug --verbose + + # This runs after all of the tests, run have run. Creates a cleaned up version of the + # distro, and then creates the artifact to push up to S3 or wherever + artifacts: + name: 'Create dev build' + needs: build + runs-on: 'ubuntu-18.04' + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + + - uses: olegtarasov/get-tag@v2.1 + id: tagName + + # Configure Caching + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + # Dependencies + - name: 'Install Release Dependencies' + run: | + rm -rf vendor + sudo npm i tar-to-zip -g + composer self-update --1 + composer install --no-dev --prefer-dist --no-interaction --verbose + sudo chmod +x ./.github/scripts/* + + - name: Get version + run: .github/scripts/version.sh + + - name: Build Distro + run: .github/scripts/build.sh + + - name: Upload S3 + uses: shallwefootball/s3-upload-action@v1.1.3 + with: + aws_key_id: ${{ secrets.S3_BUILD_ARTIFACTS_ACCESS_KEY_ID }} + aws_secret_access_key: ${{ secrets.S3_BUILD_ARTIFACTS_SECRET_ACCESS_KEY}} + aws_bucket: ${{ secrets.S3_BUCKET_NAME }} + source_dir: 'dist' + destination_dir: '' + + - name: Discord notification + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + uses: Ilshidur/action-discord@0.3.0 + with: + # DISCORD_MSG is defined in versions.sh + args: '{{ DISCORD_MSG }}' + + # This runs after all of the tests, run have run. Creates a cleaned up version of the + # distro, and then creates the artifact to push up to S3 or wherever + # https://github.com/actions/create-release + release: + name: 'Create Release' + needs: build + runs-on: 'ubuntu-18.04' + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + + - uses: olegtarasov/get-tag@v2.1 + id: tagName + + # Configure Caching + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + # Dependencies + - name: 'Install Release Dependencies' + run: | + rm -rf vendor + sudo npm i tar-to-zip -g + composer self-update --1 + composer install --no-dev --prefer-dist --no-interaction --verbose + sudo chmod +x ./.github/scripts/* + + - name: Get version + run: .github/scripts/version.sh + + - name: Build Distro + run: .github/scripts/build.sh + + - name: Upload S3 + uses: shallwefootball/s3-upload-action@v1.1.3 + with: + aws_key_id: ${{ secrets.S3_BUILD_ARTIFACTS_ACCESS_KEY_ID }} + aws_secret_access_key: ${{ secrets.S3_BUILD_ARTIFACTS_SECRET_ACCESS_KEY}} + aws_bucket: ${{ secrets.S3_BUCKET_NAME }} + source_dir: 'dist' + destination_dir: '' + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Get version + run: .github/scripts/version.sh + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: true + prerelease: false + + # Upload the tar file to the release + - name: Upload Tar Asset + id: upload-tar-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/{{TAR_NAME}} + asset_name: '{{ TAR_NAME }}' + asset_content_type: application/gzip + + # upload the zip file to the release + - name: Upload Zip Asset + id: upload-zip-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/{{ZIP_NAME}} + asset_name: '{{ ZIP_NAME }}' + asset_content_type: application/zip + + - name: Discord notification + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + uses: Ilshidur/action-discord@0.3.0 + with: + # DISCORD_MSG is defined in versions.sh + args: '{{ DISCORD_MSG }}' \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a88d8153..00000000 --- a/.travis.yml +++ /dev/null @@ -1,162 +0,0 @@ -# -# Travis CI config file -# - -language: php -php: - - '7.4' - - '7.3' - -#env: -# - DB=mysql -# - DB=mariadb - -cache: - # Cache lives for 10 min - # Default of 3m might not be long enough for all the runs - timeout: 600 - directories: - - "$HOME/.composer/cache" - - "$HOME/.npm" - -services: -- mysql - -#addons: -# mariadb: '10.2' - -install: - - php --version - - mysql --version - # Downgrade composer version to 1.x - - composer self-update --1 - - composer install --dev --no-interaction --verbose - - npm i tar-to-zip -g - - cp .travis/env.travis.php env.php - - cp .travis/phpunit.travis.xml phpunit.xml - -before_script: - - php artisan database:create --reset - - php artisan migrate:refresh --seed - -script: - - vendor/bin/php-cs-fixer fix --config=.php_cs -v --dry-run --diff --using-cache=no - - vendor/bin/phpunit --debug --verbose - -after_failure: - - cat storage/logs/*.log - -# Refer to: https://github.com/doctrine/dbal/blob/master/.travis.yml#L39 -jobs: - include: - # Different test stages -# - stage: Test -# name: PHP 7.2 + MySQL 5.7 -# php: 7.2 -# env: DB=mysql -# services: -# - mysql -# - stage: Test -# name: PHP 7.3 + MySQL 5.7 -# php: 7.3 -# env: DB=mysql -# services: -# - mysql -# - stage: Test -# name: PHP 7.4 + MySQL 5.7 -# php: 7.4 -# env: DB=mysql -# services: -# - mysql -# - stage: Test -# name: PHP 7.2 + MariaDB 10.1 -# php: 7.2 -# env: DB=mariadb -# addons: -# mariadb: '10.1' -# - stage: Test -# name: PHP 7.3 + MariaDB 10.1 -# php: 7.3 -# env: DB=mariadb -# addons: -# mariadb: '10.1' -# - stage: Test -# name: PHP 7.4 + MariaDB 10.1 -# php: 7.4 -# env: DB=mariadb MARIADB_VERSION=10.1 -# addons: -# mariadb: '10.1' -# - stage: Test -# name: PHP 7.2 + MariaDB 10.2 -# php: 7.2 -# env: DB=mariadb -# addons: -# mariadb: '10.2' -# - stage: Test -# name: PHP 7.3 + MariaDB 10.3 -# php: 7.3 -# env: DB=mariadb -# addons: -# mariadb: '10.2' -# - stage: Test -# name: PHP 7.4 + MariaDB 10.2 -# php: 7.4 -# env: DB=mariadb -# addons: -# mariadb: '10.2' -# - stage: Test -# name: PHP 7.2 + MariaDB 10.3 -# php: 7.2 -# env: DB=mariadb -# addons: -# mariadb: '10.3' -# - stage: Test -# name: PHP 7.3 + MariaDB 10.3 -# php: 7.3 -# env: DB=mariadb -# addons: -# mariadb: '10.3' -# - stage: Test -# name: PHP 7.4 + MariaDB 10.3 -# php: 7.4 -# env: DB=mariadb -# addons: -# mariadb: '10.3' - - # Just packages up a release - - stage: package - script: skip - before_deploy: - - curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/6b10798/install | bash - - # Configure the conditional deployment - # https://docs.travis-ci.com/user/deployment/#examples-of-conditional-deployment - deploy: - - provider: script - skip_cleanup: true - script: ./.travis/deploy_script.sh - on: - all_branches: true - repo: nabeelio/phpvms - php: '7.4' - tags: false - - # RELEASE STAGE - # Only runs when there's a tag applied to this release (tag should be the version) - # This uses Github Releases and posts it there (provider: releases) - # https://docs.travis-ci.com/user/deployment/releases - - stage: release - script: skip - before_deploy: - - curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/6b10798/install | bash - - ./.travis/deploy_script.sh - deploy: - provider: releases - skip_cleanup: true - api_key: $GITHUB_TOKEN - file_glob: true - file: build/* - on: - tags: true - repo: nabeelio/phpvms - php: '7.4'