Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  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

    Get this URL by looking

    . The git repository to deploy to can be found in your web host…

    1. Pantheon: Look at the Pantheon Dashboard, and clicking on the Connection Info button.click on “Clone with Git”

      Image Added

      ⚠️ Maybe obvious, but since the pantheon command that you see in the image, also contains the git clone part at the beginning and the <name-of-the-repository> at the end, you want to make sure to strip them out. A correct repo address should look something like this:

      Code Block
      languagebash
      ssh://codeserver.dev.a0303130-7e6d-48fa-ac23-7dc5b5fe1d92@codeserver.dev.a0303130-7e6d-48fa-ac23-7dc5b5fe1d92.drush.in:2222/~/repository.git

    2. Acquia: Look at your Acquia Dashboard, and click “Overview”. Move your eyes over to “Git URL”

      Image Added
  2. Add the Git Repository as a “DEPLOY_REPO” variable on the Variables screen at https://github.com/REPO/settings/variables/actions . For example: https://github.com/kalamuna/gbz4/settings/variables/actions

    Image Modified
  3. Copy the following YAML script to `.github/workflows/build-and-deploy.ymlyml`

Code Block
languageyaml
# 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
# TODO: Avoid pushing Pantheon repo bloat by only pushing branches if they have a pull request, or branches that are like GBZ-1234.

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@v3
      with:
        fetch-depth: 0

    # Running PHP and Composer is only required when it's not Pantheon.
    # - name: PHP
    #   uses: shivammathur/setup-php@v2
    #   with:
    #     php-version: "8.1.11"

    # - name: Composer
    #   uses: ramsey/composer-install@v2
    #   with:
    #     composer-options: "--prefer-dist --ignore-platform-reqs"
    
    # TODO: Add Terminus integration?

    # Node.js steps not needed on Pantheon.
    # TODO: Automate determining whether the site is Pantheon?
    - name: Node.js - Check if Required
      id: nodejsrequired
      uses: andstor/file-existence-action@v2
      with:
        files: "package.json"

    - name: Node.js - Configure
      uses: actions/setup-node@v3
      if: steps.nodejsrequired.outputs.files_exists == 'true'
      with:
        node-version: 16
        cache: 'npm'
        cache-dependency-path: package-lock.json

    - name: Node.js - Install
      run: npm ci
      if: steps.nodejsrequired.outputs.files_exists == 'true'

    - name: Node.js - Test
      run: npm test
      if: steps.nodejsrequired.outputs.files_exists == 'true'

    - name: Commit
      run: |
          git config --global user.name "${{ vars.KALABOT_GIT_NAME }}"
          git config --global user.email "${{ vars.KALABOT_GIT_EMAIL }}"
          rmmv .gitignore
          mv -f .gitignore-deploy .gitignore
          find web -type d -name .git -print0|xargs -0 rm -rf
          find docroot -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##*/}

  1. Make sure that the repo contains .gitignore-deploy file.
    as seen in the build-and-deploy.yaml above, we are copying the contents of .gitignore-deploy to .gitignore here: mv -f .gitignore-deploy .gitignore so make sure that that file is present in the repo. The content of the file depends on the type of project that you are setting up and usually is a 1:1 match to the .gitginrore unless we add some special host-related stuff to it.

Deploy Tags in New Relic

TODO

...