Giter Club home page Giter Club logo

Comments (14)

antonmedv avatar antonmedv commented on June 17, 2024 1

Yes this can be loaded from the github secrets this is like a special field in settings with the hub

from action.

jasperf avatar jasperf commented on June 17, 2024 1

On using build matrices I found an explanation here https://docs.github.com/en/actions/using-jobs/using-a-build-matrix-for-your-jobs and example

strategy:
  matrix:
    node: [10, 12, 14]
steps:
  # Configures the node version used on GitHub-hosted runners
  - uses: actions/setup-node@v2
    with:
      # The Node.js version to configure
      node-version: ${{ matrix.node }}

Thanks to @antonmedv feedback and some more reading I am slowly starting to understand. Thanks Anton!

from action.

jasperf avatar jasperf commented on June 17, 2024

Perhaps I need to something like mentioned at #4

name: Deploy

on:
  # Run on pushes to `staging` branch only.
  push:
    paths-ignore:
      - '**.md'
    branches:
      - staging
      - '!main'
  # Allow manually triggering the workflow. Used for production deploy
  workflow_dispatch:

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        php: [7.4]
        node: [12.x]

    steps:
      - name: Checkout the repo
        uses: actions/checkout@v2

      - name: PHP setup
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: none
          tools: composer:v2, deployer, wp-cli

      - name: Use Node.js ${{ matrix.node }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}

      - name: Deploy to staging
        if: ${{ github.ref == 'refs/heads/staging' }}
        uses: deployphp/action@master
        with:
          private-key: ${{ secrets.STAGING_KEY }}
          dep: deploy ${{ secrets.ADMIN_USER }} ${{ secrets.ADMIN_EMAIL }} ${{ secrets.ADMIN_PASSWORD }} staging -v

      - name: Deploy to production
        if: ${{ github.ref == 'refs/heads/main' }}
        uses: deployphp/action@master
        with:
          private-key: ${{ secrets.PRODUCTION_KEY }}
          dep: deploy ${{ secrets.ADMIN_USER }} ${{ secrets.ADMIN_EMAIL }} ${{ secrets.ADMIN_PASSWORD }} production

Just not sure how {{ matrix.node }} and {{ secrets.ADMIN_PASSWORD }} would load. Also i do not need the password stuff I would think doing all with ssh keys so that part more like the README example:

name: deploy

on: push

# It is important to specify "concurrency" for the workflow,
# to prevent concurrency between different deploys.
concurrency: production_environment

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.0'

      - name: Deploy
        uses: deployphp/action@v1
        with:
          private-key: ${{ secrets.PRIVATE_KEY }}
          dep: deploy

from action.

antonmedv avatar antonmedv commented on June 17, 2024

Secret come from girl ha s had js ssh

from action.

jasperf avatar jasperf commented on June 17, 2024

@antonmedv Not quite certain what you mean here.. You mean that secrets.PRIVATE_KEY loads ssh key from Github settings?

Would be nice to have the README example action.yml updated with staging and master like the other user showed. Especially

steps:
  - name: Checkout the repo
    uses: actions/checkout@v2

  - name: PHP setup
    uses: shivammathur/setup-php@v2
    with:
      php-version: ${{ matrix.php }}
      coverage: none
      tools: composer:v2, deployer, wp-cli

  - name: Use Node.js ${{ matrix.node }}
    uses: actions/setup-node@v1
    with:
      node-version: ${{ matrix.node }}

Is useful, but again I wonder what matrix.node loads..? It loads Node from the setup-node here?

from action.

antonmedv avatar antonmedv commented on June 17, 2024

And for simple environment variables can be also just need to assign environment variable from the stickers and of course go to settings of your repository and seconds down.

from action.

jasperf avatar jasperf commented on June 17, 2024

Got this now

name: deploy

on:
  # Trigger the workflow on push or pull request,
  # but only for the master branch
  # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

concurrency: production_environment

# on: push

# It is important to specify "concurrency" for the workflow,
# to prevent concurrency between different deploys.
# concurrency: production_environment

jobs:
  php-cs-fixer:
    runs-on: ubuntu-latest

    steps:
        -   name: Checkout code
            uses: actions/checkout@v2
            with:
                ref: ${{ github.head_ref }}

        -   name: Run PHP CS Fixer
            uses: docker://oskarstark/php-cs-fixer-ga
            with:
                args: --config=.php-cs-fixer.dist.php --allow-risky=yes

        -   name: Commit changes
            uses: stefanzweifel/git-auto-commit-action@v4
            with:
                commit_message: Fix styling
  deploy:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        php: [8.1]
        node: [14.x]

    steps:
      - name: Checkout the repo
        uses: actions/checkout@v2

      - name: PHP setup
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: none
          tools: composer:v2, deployer
          
      - name: Use Node.js ${{ matrix.node }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}
        run: npm install
        run: npm run prod

      - name: Deploy
        uses: deployphp/action@v1
        with:
          # Private key for connecting to remote hosts. To generate private key:
          # `ssh-keygen -o -t rsa -C '[email protected]'`.
          # Required.
          private-key: ${{ secrets.PRIVATE_KEY }}
          dep: deploy

But hitting

Annotations
1 error
Invalid workflow file: .github/workflows/ci.yml#L64
The workflow is not valid. .github/workflows/ci.yml (Line: 64, Col: 9): Unexpected value 'run' .github/workflows/ci.yml (Line: 65, Col: 9): 'run' is already defined

and it ran right away, which I did not really want... perhaps I need to change the branch as well.

from action.

antonmedv avatar antonmedv commented on June 17, 2024

Looks yaml file has some different from different spaces instant before run

from action.

jasperf avatar jasperf commented on June 17, 2024

@antonmedv was true on some of the spacing but running npm run prod I still cannot manage. May need to define command here like we can in deploy.yml but not sure yet how. Now have

name: deploy

on:
  # Run on pushes to `staging` branch only.
  push:
    paths-ignore:
      - '**.md'
    branches:
      - staging
      - '!main'
  # Allow manually triggering the workflow. Used for production deploy
  workflow_dispatch:

concurrency: production_environment

# on: push

# It is important to specify "concurrency" for the workflow,
# to prevent concurrency between different deploys.
# concurrency: production_environment

jobs:
  deploy:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        php: [8.1]
        node: [14.x]

    steps:
      - name: Checkout the repo
        uses: actions/checkout@v2

      - name: PHP setup
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: none
          tools: composer:v2, deployer
          
      - name: Use Node.js ${{ matrix.node }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}
        run: npm install
        # run: npm run prod
        # npm:run:prod:
        # - run: 'cd {{release_path}} && npm run prod'

      - name: Deploy to staging
        if: ${{ github.ref == 'refs/heads/staging' }}
        uses: deployphp/action@master
        with:
          # Private key for connecting to remote hosts. To generate private key:
          # `ssh-keygen -o -t rsa -C '[email protected]'`.
          # Required.
          private-key: ${{ secrets.PRIVATE_KEY }}
          dep: deploy


      - name: Deploy to production
        if: ${{ github.ref == 'refs/heads/master' }}
        uses: deployphp/action@master
        with:
          # Private key for connecting to remote hosts. To generate private key:
          # `ssh-keygen -o -t rsa -C '[email protected]'`.
          # Required.
          private-key: ${{ secrets.PRIVATE_KEY }}
          dep: deploy

from action.

jasperf avatar jasperf commented on June 17, 2024

Checking https://gist.github.com/cagartner/27052b0bccb99c74d8616a943426b390 I might need

- run: npm install
- run: npm run prod
# npm:run:prod:
# - run: 'cd {{release_path}} && npm run prod'

but wonder if I need to change path inside the image and if all this then adds assets to repository. Not sure yet.

from action.

jasperf avatar jasperf commented on June 17, 2024

Well, perhaps I need to use this block

- name: Commit built assets
  run: |
    git config --local user.email "[email protected]"
    git config --local user.name "GitHub Action"
    git checkout -B deploy
    git add -f public/
    git commit -m "Build front-end assets"
    git push -f origin deploy

in my ci.yml action as well:

name: deploy

on:
  # Run on pushes to `staging` branch only.
  push:
    paths-ignore:
      - '**.md'
    branches:
      - staging
      - '!main'
  # Allow manually triggering the workflow. Used for production deploy
  workflow_dispatch:

concurrency: production_environment

# on: push

# It is important to specify "concurrency" for the workflow,
# to prevent concurrency between different deploys.
# concurrency: production_environment

jobs:
  deploy:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        php: [8.1]
        node: [14.x]

    steps:
      - name: Checkout the repo
        uses: actions/checkout@v2

      - name: PHP setup
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: none
          tools: composer:v2, deployer
          
      - name: Use Node.js ${{ matrix.node }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}
      - run: npm install
      - run: npm run production
      - name: Commit built assets
        run: |
          git config --local user.email "[email protected]"
          git config --local user.name "GitHub Action"
          git checkout -B deploy
          git add -f public/
          git commit -m "Build front-end assets"
          git push -f origin deploy

      - name: Deploy to staging
        if: ${{ github.ref == 'refs/heads/staging' }}
        uses: deployphp/action@master
        with:
          # Private key for connecting to remote hosts. To generate private key:
          # `ssh-keygen -o -t rsa -C '[email protected]'`.
          # Required.
          private-key: ${{ secrets.PRIVATE_KEY }}
          dep: deploy


      - name: Deploy to production
        if: ${{ github.ref == 'refs/heads/master' }}
        uses: deployphp/action@master
        with:
          # Private key for connecting to remote hosts. To generate private key:
          # `ssh-keygen -o -t rsa -C '[email protected]'`.
          # Required.
          private-key: ${{ secrets.PRIVATE_KEY }}
          dep: deploy

Question remains though... if I build these assets on the image/github do these github acctions including push also happen on Github?

@antonmedv Do you build locally? Or do you add it to deploy.yml and bujld npm assets on the server?

from action.

antonmedv avatar antonmedv commented on June 17, 2024

Yes you can simply Luther and then upload it to destination this is what I do and you can do it both ways I prefer to do from the plural

from action.

jasperf avatar jasperf commented on June 17, 2024

@antonmedv think you made typo there. What do you mean by "Luther then upload it to destination"? You build on Github using a Github action like I am suggesting here? I mean like:

  • locally edit/add files
  • push to Github repository
  • run Github action to set up image
  • run action to npm install and npm run production
  • commit on same image / repository
  • deploy to server
  • run deploy.yml there including:
    • deploy:prepare
    • deploy:vendors
    • artisan:storage:link
    • artisan:view:cache
    • artisan:config:cache
    • artisan:optimize
    • artisan:migrate
    • artisan:queue:restart
    • artisan:horizon:terminate
    • deploy:publish

Or do you do more on Github action?

deploy.yml now with npm run prod included and ci.yml not in use:

import:
  - recipe/laravel.php
  - contrib/php-fpm.php
  - contrib/npm.php

config:
  application: 'our-app'
  remote_user: forge
  deploy_path: '~/{{hostname}}'
  repository: '[email protected]:app/our-app.git'
  php_fpm_version: '8.0'
  keep_releases: '10'
  shared_files: 
    - '.env'
    - '.transip_private_key'
    - 'storage/app/exact.api.json'
  shared_dirs:
    - 'bootstrap/cache'
    - 'public/uploads'
    - 'public/published'
    - 'storage/framework/cache'
    - 'storage/framework/sessions'
    - 'storage/framework/views'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/downloads'
    - 'storage/app/modules'
    - 'storage/app/public'
  writable_dirs:
    - 'public/uploads'
    - 'public/published'
    - 'storage/framework/cache/data'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/downloads'
    - 'storage/app/modules'
    - 'storage/app/public'

hosts:
  prod:
    hostname: 'site.com'
  staging:
    hostname: 'staging.site.com'

tasks:
  deploy:
    - deploy:prepare
    - deploy:vendors
    - artisan:storage:link
    - artisan:view:cache
    - artisan:config:cache
    - artisan:optimize
    - artisan:migrate
    - npm:install
    - npm:run:prod
    - artisan:queue:restart    
    - artisan:horizon:terminate
    - deploy:publish
  npm:run:prod:
    - run: 'cd {{release_path}} && npm run prod'

after:
  deploy:symlink: php-fpm:reload
  deploy:failed: deploy:unlock

from action.

jasperf avatar jasperf commented on June 17, 2024

Found some code at https://gist.github.com/cagartner/27052b0bccb99c74d8616a943426b390 for building including npm and creating a temporary commit. Can then add your deployment action after I think:

name: CD

on:
  push:
    branches: [ production ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        token: ${{ secrets.PUSH_TOKEN }}
    - name: Set up Node
      uses: actions/setup-node@v1
      with:
        node-version: '12.x'
    - run: npm install
    - run: npm run production
    - name: Commit built assets
      run: |
        git config --local user.email "[email protected]"
        git config --local user.name "GitHub Action"
        git checkout -B deploy
        git add -f public/
        git commit -m "Build front-end assets"
        git push -f origin deploy
    - name: Deploy
        uses: deployphp/action@v1
        with:
          # Private key for connecting to remote hosts. To generate private key:
          # `ssh-keygen -o -t rsa -C '[email protected]'`.
          # Required.
          private-key: ${{ secrets.PRIVATE_KEY }}
          dep: deploy

Well it is at least closer again. Just do not follow git add -f public/... Do see it at https://github.com/henrylemmon/laravel-8-fortify-auth-with-tests/blob/master/.github/workflows/main.yml as well though. And I could keep deploy.yml for general build details in the repository as well:

import:
  - recipe/laravel.php
  - contrib/php-fpm.php
  - contrib/npm.php

config:
  application: 'app-app'
  remote_user: forge
  deploy_path: '~/{{hostname}}'
  repository: '[email protected]:app/app-app.git'
  php_fpm_version: '8.0'
  keep_releases: '10'
  shared_files: 
    - '.env'
    - '.transip_private_key'
    - 'storage/app/exact.api.json'
  shared_dirs:
    - 'bootstrap/cache'
    - 'public/uploads'
    - 'public/published'
    - 'public/images'
    - 'public/downloads'
    - 'storage/framework/cache'
    - 'storage/framework/sessions'
    - 'storage/framework/views'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/downloads'
    - 'storage/app/modules'
    - 'storage/app/public'
  writable_dirs:
    - 'public/uploads'
    - 'public/published'
    - 'storage/framework/cache/data'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/downloads'
    - 'storage/app/modules'
    - 'storage/app/public'

hosts:
  prod:
    hostname: 'app.com'
  staging:
    hostname: 'staging.app.com'

tasks:
  deploy:
    - deploy:prepare
    - deploy:vendors
    - artisan:storage:link
    - artisan:view:cache
    - artisan:config:cache
    - artisan:optimize
    - artisan:migrate
    # - npm:install
    # - npm:run:prod
    - artisan:queue:restart    
    - artisan:horizon:terminate
    - deploy:publish
  # npm:run:prod:
  #   - run: 'cd {{release_path}} && npm run prod'

after:
  deploy:symlink: php-fpm:reload
  deploy:failed: deploy:unlock

from action.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.