Whenever you push your code, Semaphore will automatically run your build, test and deploy pipeline
Install the sem CLI and connect to your organization.
curl https://storage.googleapis.com/sem-cli-releases/get.sh | bash
sem connect ORGANIZATION.semaphoreci.com ACCESS_TOKENThen run sem init to create a semaphore.yml file.
Blocks are used to define what to do at each step in the pipeline. For most of our projects, we have 3-4 blocks: setup, linters, tests and build.
All the commands needed to run your app should be in the first block. For example:
blocks:
- name: Setup
task:
prologue:
commands:
- checkout // clones the github repo of the project to the job's VM environment.
- cache restore node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock)
jobs:
- name: Install dependencies
commands:
- yarn install
epilogue:
commands:
- cache delete node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock)
- cache store node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock) node_modulesPut the main task for the block under jobs. Use prologue and epilogue for caching and other commands.
Since jobs each have their own VM environment, we need to cache dependencies to be able to reuse them and to prevent slowing down the pipeline.
While blocks run one after the other, jobs can run in parallel. This is useful for linter commands. For example:
- name: "Linter"
task:
prologue:
commands:
- checkout
- cache restore node-modules-$(checksum yarn.lock)
jobs:
- name: Stylelint
commands:
- yarn stylelint
- name: Eslint
commands:
- yarn eslint
- name: Prettier.js
commands:
- yarn prettier
- name: Flow
commands:
- yarn flowPromotions are used to move to a different pipeline. Add one under the blocks in your semaphore.yml file.
promotions:
- name: Production deploy
pipeline_file: production-deploy.ymlDeployment can be done manually or automatically. For example:
promotions:
- name: Staging deploy // Auto
pipeline_file: staging-deploy.yml
auto_promote_on:
- result: passed
branch:
- develop
- name: Production deploy // Manual
pipeline_file: production-deploy.yml