|
| 1 | +on: |
| 2 | + pull_request: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + - develop |
| 7 | + schedule: |
| 8 | + - cron: '30 3 * * *' |
| 9 | + |
| 10 | +name: EE test & build |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + build: #--------------------------------------------------------------------- |
| 15 | + name: Build Phar |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Check out source code |
| 19 | + uses: actions/checkout@v2 |
| 20 | + |
| 21 | + - name: Get Composer cache directory |
| 22 | + id: composer-cache |
| 23 | + run: echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 24 | + |
| 25 | + - name: Set up Composer caching |
| 26 | + uses: actions/cache@v2 |
| 27 | + env: |
| 28 | + cache-name: cache-composer-dependencies |
| 29 | + with: |
| 30 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 31 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 32 | + restore-keys: | |
| 33 | + ${{ runner.os }}-composer- |
| 34 | +
|
| 35 | + - name: Set up PHP |
| 36 | + uses: shivammathur/setup-php@v2 |
| 37 | + with: |
| 38 | + php-version: '7.3' |
| 39 | + coverage: none |
| 40 | + tools: composer |
| 41 | + extensions: pcntl, curl, sqlite3, zip, dom, mbstring, json |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + cd "$GITHUB_WORKSPACE" |
| 46 | + # Run composer install for master else update. |
| 47 | + if [[ "$GITHUB_REF" = "refs/heads/master" ]]; then |
| 48 | + composer install --no-dev --no-progress --no-interaction |
| 49 | + else |
| 50 | + sed -i 's/\(easyengine\/.*\):\ \".*\"/\1:\ \"dev-develop\"/' composer.json |
| 51 | + composer update --prefer-dist --no-progress --no-interaction |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Setup EE version |
| 55 | + run: | |
| 56 | + cd "$GITHUB_WORKSPACE" |
| 57 | + if [[ "$GITHUB_REF" != $DEPLOY_BRANCH ]]; then |
| 58 | + CLI_VERSION=$(head -n 1 VERSION) |
| 59 | + CLI_VERSION="$(echo $CLI_VERSION | xargs)" |
| 60 | + CLI_VERSION+="-nightly-$(git rev-parse --short HEAD)" |
| 61 | + echo $CLI_VERSION > VERSION |
| 62 | + echo "$CLI_VERSION" > VERSION |
| 63 | + fi |
| 64 | + env: |
| 65 | + DEPLOY_BRANCH: "refs/heads/master" |
| 66 | + |
| 67 | + |
| 68 | + - name: Upload EE version |
| 69 | + uses: actions/upload-artifact@v2 |
| 70 | + with: |
| 71 | + name: cli_version |
| 72 | + path: VERSION |
| 73 | + |
| 74 | + - name: Build the Phar file |
| 75 | + run: php -dphar.readonly=0 utils/make-phar.php easyengine.phar |
| 76 | + |
| 77 | + - name: Check phar |
| 78 | + run: sudo ./easyengine.phar cli info |
| 79 | + |
| 80 | + - name: Upload built Phar file |
| 81 | + uses: actions/upload-artifact@v2 |
| 82 | + with: |
| 83 | + name: easyengine-phar |
| 84 | + path: easyengine.phar |
| 85 | + |
| 86 | + test: #---------------------------------------------------------------------- |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: [build] |
| 89 | + name: Behat Tests |
| 90 | + steps: |
| 91 | + - name: Check out source code |
| 92 | + uses: actions/checkout@v2 |
| 93 | + |
| 94 | + - name: Get Composer cache directory |
| 95 | + id: composer-cache |
| 96 | + run: echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 97 | + |
| 98 | + - name: Set up Composer caching |
| 99 | + uses: actions/cache@v2 |
| 100 | + env: |
| 101 | + cache-name: cache-composer-dependencies |
| 102 | + with: |
| 103 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 104 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 105 | + restore-keys: | |
| 106 | + ${{ runner.os }}-composer- |
| 107 | +
|
| 108 | + - name: Set up PHP |
| 109 | + uses: shivammathur/setup-php@v2 |
| 110 | + with: |
| 111 | + php-version: '7.3' |
| 112 | + coverage: none |
| 113 | + tools: composer |
| 114 | + extensions: pcntl, curl, sqlite3, zip, dom, mbstring, json |
| 115 | + |
| 116 | + - name: Update docker |
| 117 | + run: | |
| 118 | + sudo apt purge nginx nginx-common docker docker-engine docker.io docker-ce containerd runc |
| 119 | + curl -fsSL https://get.docker.com/ | sudo bash |
| 120 | + sudo systemctl restart docker.service |
| 121 | +
|
| 122 | + - name: Install docker-compose |
| 123 | + run: | |
| 124 | + VERSION=$(curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | |
| 125 | + grep '"tag_name":' | |
| 126 | + sed -E 's/.*"([^"]+)".*/\1/' |
| 127 | + ) |
| 128 | + sudo curl -L "https://github.com/docker/compose/releases/download/$VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose |
| 129 | +
|
| 130 | + - name: Install dependencies |
| 131 | + run: | |
| 132 | + cd "$GITHUB_WORKSPACE" |
| 133 | + # Run composer install for master else update. |
| 134 | + if [[ "$GITHUB_REF" = "refs/heads/master" ]]; then |
| 135 | + composer install --prefer-dist --no-progress --no-interaction |
| 136 | + else |
| 137 | + sed -i 's/\(easyengine\/.*\):\ \".*\"/\1:\ \"dev-develop\"/' composer.json |
| 138 | + composer update --prefer-dist --no-progress --no-interaction |
| 139 | + fi |
| 140 | +
|
| 141 | + - name: Test |
| 142 | + shell: 'script -q -e -c "bash {0}"' |
| 143 | + run: | |
| 144 | + set -e |
| 145 | + cd $GITHUB_WORKSPACE |
| 146 | + sudo -E ./vendor/bin/behat |
| 147 | + sub_commands=( |
| 148 | + vendor/easyengine/site-command/features |
| 149 | + vendor/easyengine/site-type-php/features |
| 150 | + vendor/easyengine/site-type-wp/features |
| 151 | + ) |
| 152 | + for command in "${sub_commands[@]}"; do |
| 153 | + IFS='/' read -r -a array <<< "$command" |
| 154 | + rm -rf features/* |
| 155 | + rsync -av --delete $command/ features/ > /dev/null |
| 156 | + for file in features/*.feature; do mv "$file" "${file%.feature}_${array[2]}.feature"; done |
| 157 | + echo "Running tests for $command" |
| 158 | + sudo -E ./vendor/bin/behat |
| 159 | + done |
| 160 | + env: |
| 161 | + COMPOSE_INTERACTIVE_NO_CLI: 1 |
| 162 | + |
| 163 | + - name: Output logs |
| 164 | + if: ${{ always() }} |
| 165 | + run: | |
| 166 | + [[ -f "/opt/easyengine/logs/install.log" ]] && cat /opt/easyengine/logs/install.log || echo 'No install log.' |
| 167 | + [[ -f "/opt/easyengine/logs/ee.log" ]] && cat /opt/easyengine/logs/ee.log || echo 'No run log.' |
| 168 | +
|
| 169 | + deploy: #----------------------------------------------------------------------- |
| 170 | + name: Deploy Phar |
| 171 | + if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' |
| 172 | + runs-on: ubuntu-latest |
| 173 | + needs: [build, test] |
| 174 | + |
| 175 | + steps: |
| 176 | + - name: Check out builds repository |
| 177 | + uses: actions/checkout@v2 |
| 178 | + with: |
| 179 | + repository: easyengine/easyengine-builds |
| 180 | + token: ${{ secrets.BOT_TOKEN }} |
| 181 | + |
| 182 | + - name: Download built Phar file |
| 183 | + uses: actions/download-artifact@v2 |
| 184 | + with: |
| 185 | + name: easyengine-phar |
| 186 | + |
| 187 | + - name: Set file name |
| 188 | + if: ${{ contains(github.ref, 'develop') }} |
| 189 | + run: | |
| 190 | + echo 'FILENAME=easyengine-nightly.phar' > $GITHUB_ENV |
| 191 | + - name: Set file name for master branch |
| 192 | + if: ${{ contains(github.ref, 'master') }} |
| 193 | + run: | |
| 194 | + echo 'FILENAME=easyengine.phar' > $GITHUB_ENV |
| 195 | +
|
| 196 | + - name: Move built Phar file into correct location |
| 197 | + run: | |
| 198 | + mv easyengine.phar phar/$FILENAME |
| 199 | +
|
| 200 | + - name: Make built Phar executable |
| 201 | + run: | |
| 202 | + chmod +x phar/$FILENAME |
| 203 | +
|
| 204 | + - name : Create hashes |
| 205 | + run: | |
| 206 | + md5sum phar/$FILENAME | cut -d ' ' -f 1 > phar/$FILENAME.md5 |
| 207 | + sha512sum phar/$FILENAME | cut -d ' ' -f 1 > phar/$FILENAME.sha512 |
| 208 | + - name: Commit files |
| 209 | + run: | |
| 210 | + git config --local user.email "[email protected]" |
| 211 | + git config --local user.name "GitHub Action" |
| 212 | + git add phar/$FILENAME phar/$FILENAME.md5 phar/$FILENAME.sha512 |
| 213 | + git commit -m "phar build: $GITHUB_REPOSITORY@$GITHUB_SHA" |
| 214 | +
|
| 215 | + - name: Push changes |
| 216 | + uses: ad-m/github-push-action@master |
| 217 | + with: |
| 218 | + github_token: ${{ secrets.BOT_TOKEN }} |
| 219 | + branch: master |
| 220 | + repository: easyengine/easyengine-builds |
0 commit comments