Created
April 11, 2023 22:56
-
-
Save muath-ye/0d249306bba223bd878f60dc079593dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Production Deployment | |
# on: | |
# push: | |
# branches: | |
# - production | |
on: [workflow_dispatch] | |
jobs: | |
prepare-servers-connection: | |
name: "Connecting to: ${{ vars.SERVER_NAME }}" | |
runs-on: ubuntu-latest | |
steps: | |
- name: executing remote ssh commands using password | |
uses: appleboy/ssh-action@v0.1.9 | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
password: ${{ secrets.SSH_PASS }} | |
port: ${{ secrets.SSH_PORT }} | |
script: whoami | |
create-deployment-artifacts: | |
name: Create deployment artifacts | |
runs-on: ubuntu-latest | |
needs: prepare-servers-connection | |
steps: | |
# checkout the source code into the runner | |
- uses: actions/checkout@v2 | |
- name: Compile CSS and Javascript | |
run: | | |
npm install | |
npm run build | |
- name: Configure PHP 8.1 | |
uses: shivammathur/setup-php@master | |
with: | |
php-version: 8.1 | |
extensions: mbstring, ctype, fileinfo, openssl, PDO, bcmath, json, tokenizer, xml | |
- name: Composer install | |
run: composer install --no-dev --no-interaction --prefer-dist | |
- name: Create deployment artifact | |
env: | |
GITHUB_SHA: ${{ github.sha }} # the commit hash is to determine which version is this artifact | |
run: tar -czf "${GITHUB_SHA}".tar.gz --exclude=*.git --exclude=node_modules --exclude=tests * | |
- name: Store artifact for distribution | |
uses: actions/upload-artifact@v3 | |
with: | |
name: app-build # the name of artifact | |
path: ${{ github.sha }}.tar.gz | |
prepare-release-on-servers: | |
name: "${{ vars.SERVER_NAME }}: Prepare release" | |
runs-on: ubuntu-latest | |
needs: create-deployment-artifacts | |
steps: | |
- uses: actions/download-artifact@v2 | |
with: | |
name: app-build # the name of artifact | |
- name: Upload | |
run: sudo sshpass -p ${{ secrets.SSH_PASS }} scp -v -o "HostkeyAlgorithms=ssh-dss" -o "StrictHostKeyChecking no" -r ${{ github.sha }}.tar.gz ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ vars.PATH }}/artifacts | |
- name: Create release directories | |
run: sudo sshpass -p ${{ secrets.SSH_PASS }} -v ssh -o "HostkeyAlgorithms=ssh-dss" -o "StrictHostKeyChecking no" ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} 'cd ${{ vars.PATH }} && mkdir -p releases && mkdir -p releases/${{ github.sha }}' | |
- name: Extact archive | |
run: sudo sshpass -p ${{ secrets.SSH_PASS }} -v ssh -o "HostkeyAlgorithms=ssh-dss" -o "StrictHostKeyChecking no" ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} 'tar -xzvf ${{ vars.PATH }}/artifacts/${{ github.sha }}.tar.gz -C ${{ vars.PATH }}/releases/${{ github.sha }}' | |
- name: Remove archive | |
run: sudo sshpass -p ${{ secrets.SSH_PASS }} -v ssh -o "HostkeyAlgorithms=ssh-dss" -o "StrictHostKeyChecking no" ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} 'rm ${{ vars.PATH }}/artifacts/${{ github.sha }}.tar.gz' |
Author
muath-ye
commented
Apr 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment