|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + persist-credentials: false |
| 25 | + |
| 26 | + - name: Set up PHP |
| 27 | + uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2 |
| 28 | + with: |
| 29 | + php-version: '8.2' |
| 30 | + tools: composer |
| 31 | + |
| 32 | + - name: Check if version has changed |
| 33 | + id: check_version |
| 34 | + run: | |
| 35 | + VERSION=$(grep -oP "Version:\s*\K\d+(\.\d+)*" wcpos-webtoffee-smart-coupons.php | head -n 1) |
| 36 | + if [ -z "$VERSION" ]; then |
| 37 | + echo "Could not find plugin version in wcpos-webtoffee-smart-coupons.php" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + git fetch --tags --force |
| 42 | +
|
| 43 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + if git tag --list "v$VERSION" | grep -q .; then |
| 46 | + echo "Version has not changed. Skipping release..." |
| 47 | + echo "release=false" >> "$GITHUB_OUTPUT" |
| 48 | + else |
| 49 | + echo "Version has changed. Creating new release..." |
| 50 | + echo "release=true" >> "$GITHUB_OUTPUT" |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Install composer dependencies |
| 54 | + if: steps.check_version.outputs.release == 'true' |
| 55 | + run: composer install --no-dev --optimize-autoloader |
| 56 | + |
| 57 | + - name: Build ZIP |
| 58 | + if: steps.check_version.outputs.release == 'true' |
| 59 | + run: | |
| 60 | + rm -rf dist wcpos-webtoffee-smart-coupons.zip |
| 61 | + mkdir -p dist/wcpos-webtoffee-smart-coupons |
| 62 | +
|
| 63 | + rsync -a ./ dist/wcpos-webtoffee-smart-coupons/ \ |
| 64 | + --exclude '.git*' \ |
| 65 | + --exclude '.github/' \ |
| 66 | + --exclude 'node_modules/' \ |
| 67 | + --exclude 'tests/' \ |
| 68 | + --exclude 'vendor/' \ |
| 69 | + --exclude '.wp-env.json' \ |
| 70 | + --exclude '.wp-env.override.json' \ |
| 71 | + --exclude 'phpunit.xml.dist' \ |
| 72 | + --exclude '.phpunit.result.cache' \ |
| 73 | + --exclude 'composer.json' \ |
| 74 | + --exclude 'composer.lock' \ |
| 75 | + --exclude 'package.json' \ |
| 76 | + --exclude 'pnpm-lock.yaml' \ |
| 77 | + --exclude 'pnpm-workspace.yaml' \ |
| 78 | + --exclude 'dist/' |
| 79 | +
|
| 80 | + cd dist |
| 81 | + zip -r ../wcpos-webtoffee-smart-coupons.zip wcpos-webtoffee-smart-coupons |
| 82 | +
|
| 83 | + - name: Create release and upload ZIP |
| 84 | + if: steps.check_version.outputs.release == 'true' |
| 85 | + run: | |
| 86 | + gh release create "v${{ steps.check_version.outputs.version }}" \ |
| 87 | + wcpos-webtoffee-smart-coupons.zip \ |
| 88 | + --title "Release v${{ steps.check_version.outputs.version }}" \ |
| 89 | + --notes "Automated release for version ${{ steps.check_version.outputs.version }}" |
| 90 | + env: |
| 91 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments