Giter Site home page Giter Site logo

101-ci-cd's Introduction

Open Source 101: CI/CD

๐ŸŽฏ Goal

Develop Continuous Integration / Continuous Delivery workflows using GitHub Actions.

๐Ÿ’ป Steps

Discuss CI/CD using Visualize Git.

Using what you learned from the previous section...

1. CI: Build, test, and audit this app across the LTS and Current version of Node.js upon every push and every pull request.

Hints
  1. Uh oh, are the tests broken? ๐Ÿ˜„

  2. npm can do quite a bit, including auditing software for known vulnerabilities.

  3. Explore workflow strategy.

Solution
  1. Start with the "Node.js CI" template workflow, target the right versions of node, add npm audit:
name: Continuous Integration

on: [push, pull_request]

jobs:
  ci:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x, 13.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm install
    - run: npm audit
    - run: npm run build --if-present
    - run: npm test
      env:
        CI: true

  1. npm audit fix
  2. Fix the broken test.

2. CD: Publish this library to GitHub Packages upon push to the master branch.

Hints
  1. Is there another starter template workflow that can help?

  2. GitHub Packages used scoped NPM packages โ€“ you'll need to adjust the package name in package.json (and package-lock.json via npm install) to your username.

  3. Can you combine CI and CD into one workflow?

Solution
name: Continuous Integration and Delivery

on: [push, pull_request]

jobs:
  ci:

    runs-on: [ubuntu-latest]

    strategy:
      matrix:
        node-version: [12.x, 13.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm install
    - run: npm audit
    - run: npm run build --if-present
    - run: npm test
      env:
        CI: true
  cd:
    
    needs: ci
    if: github.ref == 'refs/heads/master' && github.event_name == 'push'
    runs-on: [ubuntu-latest]
    
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
          scope: '@my-username'
      - run: npm i
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
    

๐Ÿ… Extra credit

  • Hook one of your own projects up to GitHub Actions CI/CD

101-ci-cd's People

Contributors

imjohnbo avatar smwentum avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.