├── .github └── workflows │ └── ci.yml ├── Dockerfile ├── README.md ├── entrypoint.sh └── tests └── deploy.php /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | workflow_dispatch: 6 | 7 | jobs: 8 | tests: 9 | runs-on: ubuntu-latest 10 | timeout-minutes: 5 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | - name: Deploy stage test 15 | id: deploy 16 | uses: ./ 17 | with: 18 | args: deploy test -f ./tests/deploy.php 19 | env: 20 | SERVER1_USER: ${{ secrets.SERVER1_USER }} 21 | SERVER1_HOSTNAME: ${{ secrets.SERVER1_HOSTNAME }} 22 | SSH_PRIVATE_KEY: ${{ secrets.TEST_SSH_PRIVATE_KEY }} 23 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4-cli-alpine 2 | 3 | LABEL "repository" = "https://github.com/musps/action-deployer-php" 4 | LABEL "homepage" = "https://github.com/musps/action-deployer-php" 5 | 6 | LABEL "com.github.actions.name"="Action - Deployer php" 7 | LABEL "com.github.actions.description"="Use your Deployer PHP script with your github action workflow." 8 | LABEL "com.github.actions.icon"="server" 9 | LABEL "com.github.actions.color"="yellow" 10 | 11 | ENV DEPLOYER_VERSION=6.8.0 12 | 13 | RUN apk update --no-cache \ 14 | && apk add --no-cache \ 15 | bash \ 16 | openssh-client \ 17 | rsync 18 | 19 | # Change default shell to bash (needed for conveniently adding an ssh key) 20 | RUN sed -i -e "s/bin\/ash/bin\/bash/" /etc/passwd 21 | 22 | RUN curl -L https://deployer.org/releases/v$DEPLOYER_VERSION/deployer.phar > /usr/local/bin/deployer \ 23 | && chmod +x /usr/local/bin/deployer 24 | 25 | COPY entrypoint.sh /entrypoint.sh 26 | 27 | RUN chmod +x /entrypoint.sh 28 | 29 | ENTRYPOINT ["/entrypoint.sh"] 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Action - Deployer PHP 3 | 4 | ### Usage 5 | 6 | ``` 7 | musps/action-deployer-php@master 8 | ``` 9 | 10 | ### Example 11 | 12 | ```yaml 13 | - name: Deploy to prod server 14 | uses: musps/action-deployer-php@master 15 | with: 16 | args: deploy prod 17 | env: 18 | SSH_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} 19 | ``` 20 | 21 | ### Definition 22 | 23 | * Set your ssh private key in your repository secrets. 24 | * Set the file and command as argument . 25 | * Current Deployer PHP version: `6.8.0` 26 | 27 | ### Demo workflows 28 | 29 | * Run the deployment on branch prefixed by `releases/x`. 30 | 31 | ```yaml 32 | name: Test action Deployer PHP 33 | 34 | on: 35 | push: 36 | branches: 37 | - 'releases/*' 38 | 39 | jobs: 40 | build: 41 | name: Deploy code to prod 42 | runs-on: ubuntu-latest 43 | steps: 44 | - name: Checkout 45 | uses: actions/checkout@v1 46 | - name: Deploy 47 | uses: musps/action-deployer-php@master 48 | with: 49 | args: deploy prod 50 | env: 51 | SSH_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} 52 | ``` 53 | 54 | ### About 55 | 56 | * This project is based on top of https://github.com/deployphp/deployer 57 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | if [[ -n "$REF" && -n "$SUBSTRING" ]]; then 6 | REF=${REF/$SUBSTRING/} 7 | echo "REF: $REF" 8 | fi 9 | 10 | if [ -z "$1" ]; then 11 | CMD_ARGS="" 12 | else 13 | CMD_ARGS="$@" 14 | fi 15 | 16 | mkdir -p /github/home/.ssh 17 | 18 | eval $(ssh-agent -s) 19 | 20 | echo -e "StrictHostKeyChecking no" >> /etc/ssh/ssh_config 21 | echo "$SSH_PRIVATE_KEY" | tr -d '\r' > /tmp/id_rsa 22 | chmod 600 /tmp/id_rsa 23 | ssh-add /tmp/id_rsa 24 | 25 | deployer --version 26 | deployer $CMD_ARGS -------------------------------------------------------------------------------- /tests/deploy.php: -------------------------------------------------------------------------------- 1 | stage('test') 13 | ->hostname(getenv('SERVER1_HOSTNAME')) 14 | ->port(22) 15 | ->user(getenv('SERVER1_USER')) 16 | ->set('deploy_path', '/test') 17 | ->forwardAgent(); 18 | 19 | task('deploy', [ 20 | 'deploy:prepare', 21 | 'deploy:lock', 22 | 'deploy:release', 23 | 'deploy:clear_paths', 24 | 'deploy:symlink', 25 | 'deploy:unlock', 26 | 'cleanup', 27 | 'success' 28 | ]); 29 | 30 | after('deploy:failed', 'deploy:unlock'); --------------------------------------------------------------------------------