|
| 1 | +name: Build and deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + release: |
| 6 | + types: [published] |
| 7 | +jobs: |
| 8 | + buildBackend: |
| 9 | + name: Build backend |
| 10 | + runs-on: ubuntu-latest |
| 11 | + environment: deploy_on_release |
| 12 | + steps: |
| 13 | + - name: "Checkout" |
| 14 | + uses: "actions/checkout@v4" |
| 15 | + with: |
| 16 | + ref: ${{ github.head_ref || github.ref_name }} |
| 17 | + fetch-depth: 100 |
| 18 | + - name: "install PHP and composer" |
| 19 | + uses: "shivammathur/setup-php@v2" |
| 20 | + with: |
| 21 | + coverage: "none" |
| 22 | + extensions: "intl, zip, xml, apcu" |
| 23 | + ini-values: "memory_limit=-1" |
| 24 | + php-version: "8.4" |
| 25 | + tools: "composer" |
| 26 | + - name: "Export Git repo" |
| 27 | + run: | |
| 28 | + # Remove a possibly existing extraction folder |
| 29 | + rm -rf extract |
| 30 | + # No that we are sure it's not there, create an empty extraction folder |
| 31 | + mkdir extract |
| 32 | + # Create an archive from the repository based on the given tag |
| 33 | + # and extract that into the just created extraction folder. |
| 34 | + git archive --prefix="./" --format=tar ${{ github.head_ref || github.ref_name }} .| tar xv -C extract/ |
| 35 | + # Do some shell magic to replace occurrences of the string '%release-tag%' |
| 36 | + # with the current release tag in all files within the extraction folder |
| 37 | + find extract/ -type f -exec sed -i "s/%release-tag%/:${{ github.head_ref || github.ref_name }}/" {} \; |
| 38 | + # Move into the extraction folder |
| 39 | + cd extract |
| 40 | + # Call composer install to add all your dependencies, prefer the |
| 41 | + # distribution ones and create an authoritative and optimized autoloader |
| 42 | + composer install --no-dev --prefer-dist -a |
| 43 | + # Go back one level |
| 44 | + rm -rf frontend compose* |
| 45 | + cd .. |
| 46 | + # Create the actual archive that you want to deploy |
| 47 | + tar cvzf backend-${{ github.head_ref || github.ref_name }}.tgz -C extract/ . |
| 48 | + # clean up the extraction folder |
| 49 | + rm -rf extract |
| 50 | + - uses: actions/upload-artifact@v4 |
| 51 | + with: |
| 52 | + name: backend |
| 53 | + path: backend-${{ github.head_ref || github.ref_name }}.tgz |
| 54 | + retention-days: 1 |
| 55 | + |
| 56 | + buildFrontend: |
| 57 | + name: "Build Frontend" |
| 58 | + runs-on: ubuntu-latest |
| 59 | + environment: deploy_on_release |
| 60 | + steps: |
| 61 | + - name: "Checkout" |
| 62 | + uses: "actions/checkout@v4" |
| 63 | + with: |
| 64 | + ref: ${{ github.head_ref || github.ref_name }} |
| 65 | + fetch-depth: 100 |
| 66 | + - name: "install Node" |
| 67 | + uses: actions/setup-node@v4 |
| 68 | + with: |
| 69 | + node-version: '20.x' |
| 70 | + - name: "Export Git repo" |
| 71 | + run: | |
| 72 | + # Remove a possibly existing extraction folder |
| 73 | + rm -rf extract |
| 74 | + # No that we are sure it's not there, create an empty extraction folder |
| 75 | + mkdir extract |
| 76 | + # Create an archive from the repository based on the given tag |
| 77 | + # and extract that into the just created extraction folder. |
| 78 | + git archive --prefix="./" --format=tar ${{ github.head_ref || github.ref_name }} .| tar xv -C extract/ |
| 79 | + # Do some shell magic to replace occurrences of the string '%release-tag%' |
| 80 | + # with the current release tag in all files within the extraction folder |
| 81 | + find extract/ -type f -exec sed -i "s/%release-tag%/:${{ github.head_ref || github.ref_name }}/" {} \; |
| 82 | + # Move into the extraction folder |
| 83 | + cd extract/frontend |
| 84 | + # Call Node.js install to add all your dependencies, prefer the |
| 85 | + npm ci |
| 86 | + npm run build |
| 87 | + # Go back one level |
| 88 | + cd .. |
| 89 | + rm -rf config src templates vendor frontend compose* |
| 90 | + cd .. |
| 91 | + # Create the actual archive that you want to deploy |
| 92 | + tar cvzf frontend-${{ github.head_ref || github.ref_name }}.tgz -C extract/ . |
| 93 | + # clean up the extraction folder |
| 94 | + rm -rf extract |
| 95 | + - uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: frontend |
| 98 | + path: frontend-${{ github.head_ref || github.ref_name }}.tgz |
| 99 | + retention-days: 1 |
| 100 | + |
| 101 | + buildFrontendContainer: |
| 102 | + needs: buildFrontend |
| 103 | + name: "Build Frontend-COntainer" |
| 104 | + |
| 105 | + runs-on: ubuntu-latest |
| 106 | + steps: |
| 107 | + - name: 'Checkout GitHub Action' |
| 108 | + uses: actions/checkout@main |
| 109 | + |
| 110 | + - name: 'Login to GitHub Container Registry' |
| 111 | + uses: docker/login-action@v1 |
| 112 | + with: |
| 113 | + registry: ghcr.io |
| 114 | + username: ${{github.actor}} |
| 115 | + password: ${{secrets.GITHUB_TOKEN}} |
| 116 | + |
| 117 | + - uses: actions/download-artifact@v4 |
| 118 | + with: |
| 119 | + name: frontend |
| 120 | + path: frontend-${{ github.head_ref || github.ref_name }}.tgz |
| 121 | + - name: 'Build Inventory Image' |
| 122 | + run: | |
| 123 | + docker compose build frontend |
| 124 | + docker images ls |
| 125 | + ls -al |
| 126 | +# docker push ghcr.io/<your-GitHub-username>/store:latest |
0 commit comments