GitHub

GitHub is a widely used Git hosting service that provides a robust platform for code collaboration and version control.
View as Markdown

Overview

With Knapsack, you can leverage GitHub’s extensive ecosystem, including integration with GitHub Actions for CI/CD, advanced code review features, and seamless repository management. GitHub’s user-friendly interface and powerful API make it a great choice for teams of all sizes.

Cloud Authoring

To enable Cloud Authoring with GitHub, you need to install and configure our GitHub App.

Important Steps

Step 1: Install the GitHub App

Ensure the GitHub App is installed for your Knapsack repository. This step is crucial for enabling seamless integration and functionality.

Step 2: Configure the App

Properly configure the app to authenticate and interact with your repository. This ensures smooth pull request submissions and code merging.

Permissions Required

Please note that you must have the necessary GitHub Organization permissions to install and configure the app. Without these permissions, you will not be able to complete the setup.

By following these steps, you can fully leverage Cloud Authoring capabilities with GitHub, streamlining your development workflow.

For any questions or further assistance, please reach out to our team.


GitHub Actions

Required Repository Secrets

Deployments to Heroku rely on the following repository secrets:

  1. HEROKU_EMAIL — The email associated with the Heroku account.
  2. HEROKU_API_KEY — The API Key associated with the Heroku account (found in profile settings)
  3. HEROKU_GIT_URL — Located on the app dashboard within Heroku’s admin interface

Example main.yml

1name: Main
2
3on:
4 push:
5 branches:
6 - main
7
8jobs:
9 deploy:
10 name: Deploy
11 if: github.ref == 'refs/heads/main'
12 needs: [build]
13 runs-on: ubuntu-latest
14 env:
15 HEROKU_EMAIL: ${{ secrets.HEROKU_EMAIL }}
16 HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
17 HEROKU_GIT_URL: ${{ secrets.HEROKU_GIT_URL }}
18 steps:
19 - uses: actions/checkout@v2
20 with:
21 fetch-depth: 0
22 ref: main
23 - name: write auth
24 run: |
25 cat > ~/.netrc <<EOF
26 machine git.heroku.com
27 login $HEROKU_EMAIL
28 password $HEROKU_API_KEY
29 EOF
30 - name: git push to heroku for deploy
31 run: |
32 git remote add heroku $HEROKU_GIT_URL
33 git push heroku main
34
35 build:
36 name: Build & Release
37 runs-on: ubuntu-latest
38 steps:
39 - name: Use actions/checkout@v2
40 uses: actions/checkout@v2
41 with:
42 fetch-depth: 0
43 - name: Use Node.js
44 uses: actions/setup-node@v1
45 with:
46 node-version: 18
47 - name: Handle Cache
48 uses: actions/cache@v2
49 id: cache
50 with:
51 path: |
52 node_modules
53 **/node_modules
54 ~/.cache/yarn
55 key: node-deps-${{ hashFiles('yarn.lock') }}
56 - name: Install Deps
57 if: steps.cache.outputs.cache-hit != 'true'
58 run: |
59 yarn cache clean
60 yarn install --cache-folder ~/.cache/yarn --prefer-offline --frozen-lockfile --force-node-version=16
61 env:
62 CYPRESS_INSTALL_BINARY: 0
63 - name: Run Full Build
64 run: yarn build
65 - name: Run Knapsack Test
66 run: yarn test
67 - name: Release
68 run: yarn auto shipit
69 env:
70 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Deploy Job

The deploy job is responsible for deploying the application to Heroku. It only runs when changes are pushed to the main branch. This job depends on the successful completion of the build job. Here are the steps involved:

  1. Checkout Repository: Uses the actions/checkout@v2 action to fetch the entire repository history with a fetch depth of 0. This is required for deployment.
  2. Write Authentication: Writes Heroku authentication details to the .netrc file to allow Git to authenticate with Heroku using the provided secrets (HEROKU_EMAIL and HEROKU_API_KEY).
  3. Push to Heroku: Adds Heroku as a Git remote and pushes the main branch to Heroku for deployment.

Build & Release Job

The build job handles the build and release process of the application. This job runs on every push to the main branch. Here are the steps involved:

  1. Checkout Repository: Uses the actions/checkout@v2 action to fetch the entire repository history with a fetch depth of 0. This ensures all branches and tags are available.
  2. Set Up Node.js: Sets up Node.js version 18 using the actions/setup-node@v1 action.
  3. Handle Cache: Uses the actions/cache@v2 action to cache node_modules and yarn cache directories to speed up subsequent builds. The cache key is based on the yarn.lock file hash.
  4. Install Dependencies: Installs the project dependencies using Yarn if the cache is not hit. It skips downloading the Cypress binary to speed up the CI process.
  5. Run Full Build: Builds the application by running yarn build.
  6. Run Tests: Executes the test suite using yarn test.
  7. Release: Releases the application using yarn auto shipit, which creates a release on GitHub. This step uses the GH_TOKEN secret for authentication with GitHub.