|
| 1 | +version: 2 |
| 2 | + |
| 3 | +defaults: |
| 4 | + workspace_root: &workspace_root |
| 5 | + ~/transcoder |
| 6 | + |
| 7 | + nodejs_container: &nodejs_container |
| 8 | + working_directory: *workspace_root |
| 9 | + docker: |
| 10 | + - image: circleci/node:10-stretch |
| 11 | + |
| 12 | + golang_container: &golang_container |
| 13 | + working_directory: *workspace_root |
| 14 | + docker: |
| 15 | + - image: circleci/golang:1-stretch |
| 16 | + |
| 17 | + filters: &default_filters |
| 18 | + tags: |
| 19 | + only: '/v[0-9]+(\.[0-9]+)*/' |
| 20 | + |
| 21 | + attach_workspace: &attach_workspace |
| 22 | + attach_workspace: |
| 23 | + at: *workspace_root |
| 24 | + |
| 25 | + restore_node_modules: &restore_node_modules |
| 26 | + restore_cache: |
| 27 | + name: Restore node_modules cache |
| 28 | + keys: |
| 29 | + - v1-transcoder-node-{{ .Branch }}-{{ checksum "yarn.lock" }} |
| 30 | + - v1-transcoder-node-master-{{ checksum "yarn.lock" }} |
| 31 | + - v1-transcoder-node-master- |
| 32 | + |
| 33 | +jobs: |
| 34 | + checkout: |
| 35 | + <<: *nodejs_container |
| 36 | + steps: |
| 37 | + - checkout |
| 38 | + |
| 39 | + - persist_to_workspace: |
| 40 | + root: *workspace_root |
| 41 | + paths: |
| 42 | + - ./ |
| 43 | + |
| 44 | + install: |
| 45 | + <<: *nodejs_container |
| 46 | + steps: |
| 47 | + - *attach_workspace |
| 48 | + - *restore_node_modules |
| 49 | + |
| 50 | + - restore_cache: |
| 51 | + name: Restore yarn cache |
| 52 | + keys: |
| 53 | + - v1-transcoder-yarn-{{ checksum "yarn.lock" }} |
| 54 | + - v1-transcoder-yarn- |
| 55 | + |
| 56 | + - run: |
| 57 | + name: Install dependencies |
| 58 | + command: yarn --frozen-lockfile |
| 59 | + |
| 60 | + - save_cache: |
| 61 | + name: Save yarn cache |
| 62 | + key: v1-transcoder-yarn-{{ checksum "yarn.lock" }} |
| 63 | + paths: |
| 64 | + - ~/.cache/yarn/ |
| 65 | + |
| 66 | + - save_cache: |
| 67 | + name: Save node_modules cache |
| 68 | + key: v1-transcoder-node-{{ .Branch }}-{{ checksum "yarn.lock" }} |
| 69 | + paths: |
| 70 | + - node_modules/ |
| 71 | + |
| 72 | + lint: |
| 73 | + <<: *nodejs_container |
| 74 | + steps: |
| 75 | + - *attach_workspace |
| 76 | + - *restore_node_modules |
| 77 | + |
| 78 | + - run: |
| 79 | + name: Lint |
| 80 | + command: yarn xo |
| 81 | + |
| 82 | + changelog: |
| 83 | + <<: *nodejs_container |
| 84 | + steps: |
| 85 | + - *attach_workspace |
| 86 | + - *restore_node_modules |
| 87 | + |
| 88 | + - restore_cache: |
| 89 | + name: Restore changelog cache |
| 90 | + keys: |
| 91 | + - v1-transcoder-changelog-{{ .BuildNum }} |
| 92 | + - v1-transcoder-changelog- |
| 93 | + |
| 94 | + - run: |
| 95 | + name: Generate changelog |
| 96 | + command: | |
| 97 | + if [ $CIRCLE_TAG ]; then |
| 98 | + PREV_TAG=$(git describe --abbrev=0 --tags $CIRCLE_TAG^) |
| 99 | +
|
| 100 | + echo "[+] Running for range $PREV_TAG...$CIRCLE_TAG" |
| 101 | +
|
| 102 | + node_modules/.bin/lerna-changelog --from $PREV_TAG --to $CIRCLE_TAG > CHANGELOG.md |
| 103 | + else |
| 104 | + PREV_TAG=$(git describe --abbrev=0 --tags) |
| 105 | +
|
| 106 | + echo "[+] Running from $PREV_TAG" |
| 107 | +
|
| 108 | + node_modules/.bin/lerna-changelog --from $PREV_TAG > CHANGELOG.md |
| 109 | + fi |
| 110 | +
|
| 111 | + - save_cache: |
| 112 | + name: Save changelog cache |
| 113 | + key: v1-transcoder-changelog-{{ .BuildNum }} |
| 114 | + paths: |
| 115 | + - .changelog/ |
| 116 | + |
| 117 | + - run: |
| 118 | + name: Display changelog |
| 119 | + command: cat CHANGELOG.md |
| 120 | + |
| 121 | + - persist_to_workspace: |
| 122 | + name: Persist changelog |
| 123 | + root: *workspace_root |
| 124 | + paths: |
| 125 | + - CHANGELOG.md |
| 126 | + |
| 127 | + release: |
| 128 | + <<: *golang_container |
| 129 | + steps: |
| 130 | + - *attach_workspace |
| 131 | + - *restore_node_modules |
| 132 | + |
| 133 | + - run: |
| 134 | + name: Install github-release |
| 135 | + command: go get github.com/aktau/github-release |
| 136 | + |
| 137 | + - run: |
| 138 | + name: Create GitHub release |
| 139 | + command: github-release release --user $CIRCLE_PROJECT_USERNAME --repo $CIRCLE_PROJECT_REPONAME --tag $CIRCLE_TAG --description "$(cat CHANGELOG.md)" --name $CIRCLE_TAG |
| 140 | + |
| 141 | +workflows: |
| 142 | + version: 2 |
| 143 | + |
| 144 | + push: |
| 145 | + jobs: |
| 146 | + - checkout: |
| 147 | + filters: *default_filters |
| 148 | + |
| 149 | + - install: |
| 150 | + requires: |
| 151 | + - checkout |
| 152 | + filters: *default_filters |
| 153 | + |
| 154 | + - lint: |
| 155 | + requires: |
| 156 | + - install |
| 157 | + filters: *default_filters |
| 158 | + |
| 159 | + - changelog: |
| 160 | + requires: |
| 161 | + - install |
| 162 | + filters: *default_filters |
| 163 | + |
| 164 | + - release: |
| 165 | + requires: |
| 166 | + - changelog |
| 167 | + filters: |
| 168 | + <<: *default_filters |
| 169 | + branches: |
| 170 | + ignore: /.*/ |
0 commit comments