-
Notifications
You must be signed in to change notification settings - Fork 15
115 lines (101 loc) · 4.34 KB
/
CI.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main and next branches
on:
push:
branches:
- main
- next
- v1
paths-ignore:
- '**/docs/**'
- '**.md'
pull_request:
types: [opened, synchronize, reopened, edited, ready_for_review]
paths-ignore:
- '**/docs/**'
- '**.md'
# Setup concurrency to the ref (branch / tag) that triggered the workflow
concurrency: ci-${{ github.ref }}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "CI"
CI:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Do not run if the pull request is a draft
if: ${{ !github.event.pull_request.draft && !contains(github.event.commits[0].message, '[skip build]') }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# Use fetch-depth: 0 so that all tags and branches are fetched
# Use persist-credentials: false so that the make release step uses another personal access
# token which has admin access and can push the version commit without the restriction
# of creating a pull-request.
- uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@v2
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
scope: '@farfetch'
cache: 'yarn'
always-auth: true
# This is needed for lerna to commit and push the
# new version when making a release
- name: Checkout the source branch in a pull request for lerna
if: ${{ github.event_name == 'pull_request' && startsWith(github.head_ref, 'rc/') }}
run: |
git checkout "${{ github.head_ref }}"
# This is needed for lerna to commit and push the
# new version when making a release
- name: Checkout the branch for pushes to a branch for lerna
if: ${{ github.event_name == 'push' }}
run: |
git checkout "${{ github.ref_name }}"
# Retrieves the commit message to be used in the
# make release step
- name: Get commit message
id: get-commit-message
run: |
COMMIT_MSG=$(git log -1 --pretty=format:"%s")
echo "Commit message is: ${COMMIT_MSG})"
echo ::set-output name=message::${COMMIT_MSG}
- name: Install dependencies
run: yarn install --ignore-engines --frozen-lockfile
- name: Lint
run: yarn lint
- name: Test
run: yarn test --ci
# Only make a release if it is a run of the 'main' or 'next' branches
# or a pull request that contains a 'chore: make release' message
- name: Make release
if: |
github.ref_name == 'main' ||
github.ref_name == 'next' ||
github.ref_name == 'v1' ||
(github.event_name == 'pull_request' && startsWith(github.head_ref, 'rc/'))
env:
MAKE_RELEASE_COMMIT_MESSAGE: 'chore: make release'
PUBLISH_COMMIT_MESSAGE: 'chore: publish [skip build]'
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
GIT_AUTHOR_NAME: ${{ secrets.RELEASE_BOT_GIT_NAME }}
GIT_AUTHOR_EMAIL: ${{ secrets.RELEASE_BOT_GIT_EMAIL }}
GIT_COMMITTER_NAME: ${{ secrets.RELEASE_BOT_GIT_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.RELEASE_BOT_GIT_EMAIL }}
run: |
git remote set-url origin "https://${GITHUB_TOKEN}@github.com/Farfetch/blackout.git"
SOURCE_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
if [[ ${SOURCE_BRANCH_NAME} = main || ${SOURCE_BRANCH_NAME} = v1 ]]; then
npx lerna publish --conventional-commits --message "${PUBLISH_COMMIT_MESSAGE}" --no-verify-access --yes
else
if [[ ${SOURCE_BRANCH_NAME} = next ]]; then
PRE_ID=next
else
PRE_ID=rc
fi
npx lerna publish --conventional-commits --conventional-prerelease --no-verify-access --preid ${PRE_ID} --pre-dist-tag ${PRE_ID} --message "${PUBLISH_COMMIT_MESSAGE}" --yes
fi