Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

GitHub Actions is a continuous integration system provided by GitHub. We use GitHub Actions to deploy many sites to our hosting environments.

The following is a GitHub Actions definition file that will deploy from GitHub to Pantheon for each branch. If you push to a gbz-123 branch on GitHub, it will deploy to the gbz-123 branch on Pantheon. If you push to the master branch on GitHub, it will push to the master branch on Pantheon (the DEV environment). The script uses Kalamuna’s Organizational Secrets and Variables to handle the SSH keys and configuration so that future SSH key updates are made easily.

Installation

In order to set it up…

  1. Add a Repository Variable in your repository settings at https://github.com/REPO/settings/variables/actions named DEPLOY_REPO that points to which git repository you would like it to push to

    1. For example: https://github.com/kalamuna/gbz4/settings/variables/actions

  2. Copy the following YAML script to .github/workflows/build-and-deploy.yml

# Kalamuna GitHub Actions Deployment
#
# This will deploy from GitHub to a git repository through GitHub Actions.
#
# 1. Add a DEPLOY_REPO variable to your GitHub Actions variables
#    https://github.com/kalamuna/REPO/settings/secrets/actions
#
# 2. Add this build-and-deploy.yml file to a .github/workflows folder
#
# 3. Ensure all build steps are represented

name: Build and Deploy
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:

    # Verify the DEPLOY_REPO Repository variable exists
    - name: Verify DEPLOY_REPO
      if: "${{ vars.DEPLOY_REPO == '' }}"
      run: echo "Add a DEPLOY_REPO Repository Variable at https://github.com/$GITHUB_REPOSITORY/settings/variables/actions for where to deploy to." && exit 1

    - name: Checkout
      uses: actions/checkout@v1

    - name: Node.js - Configure
      uses: actions/setup-node@v3
      with:
        node-version: 14
        cache: 'npm'
        cache-dependency-path: package-lock.json

    - name: Node.js - Install
      run: npm ci

    - name: Node.js - Test
      run: npm test

    - name: Commit
      run: |
          git config --global user.name "${{ vars.KALABOT_GIT_NAME }}"
          git config --global user.email "${{ vars.KALABOT_GIT_EMAIL }}"
          rm .gitignore
          mv .gitignore-deploy .gitignore
          find web -type d -name .git -print0|xargs -0 rm -rf
          git add .
          git commit -m "Built $GITHUB_REPOSITORY from: $GITHUB_SHA
              All code changes should be committed to: https://github.com/$GITHUB_REPOSITORY
              Any commits made directly to this Pantheon repository will be overwritten."

    - name: Configure SSH
      uses: shimataro/ssh-key-action@v2
      with:
        key: ${{ secrets.KALABOT_SSH_KEY }}
        config: ${{ vars.KALABOT_SSH_CONFIG }}
        known_hosts: unnecessary

    - name: Deploy
      env:
        deploy_repo: '${{ vars.DEPLOY_REPO }}'
      run: |
        git remote add deploy $deploy_repo
        git push --force deploy HEAD:refs/heads/${GITHUB_REF##*/}

Demonstrations

The following sites are actively using this…

  • 511

  • GBZ

  • No labels