mattermost-desktop/.circleci/config.yml
Devin Binnie 26bea631da
Add jobs for automatically building test builds for PRs (#1713)
* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP
2021-08-31 08:57:24 -04:00

641 lines
19 KiB
YAML

version: 2.1
parameters:
run_nightly:
default: false
type: boolean
orbs:
win: circleci/windows@1.0.0
aws-s3: circleci/aws-s3@2.0.0
owasp: entur/owasp@0.0.10
executors:
wine-chrome:
working_directory: ~/mattermost-desktop
docker:
- image: electronuserland/builder:wine-chrome
environment:
TAR_OPTIONS: --no-same-owner
wine-mono:
working_directory: ~/mattermost-desktop
docker:
- image: electronuserland/builder:wine-mono
mac:
working_directory: ~/mattermost-desktop
macos:
xcode: "10.3.0"
aws:
working_directory: ~/mattermost-desktop
docker:
- image: 'circleci/python:2.7'
github:
working_directory: ~/mattermost-desktop
docker:
- image: circleci/golang:1.12
commands:
notify:
description: "notify on release channel"
parameters:
message:
type: string
default: "This is the default notification message, someone forgot to add info on what to notify!"
username:
type: string
default: "MattermostRelease"
icon:
type: string
default: "https://www.mattermost.org/wp-content/uploads/2016/04/icon.png"
steps:
- run:
command: |
export VERSION=$(jq -r .version package.json)
echo '{}' | jq "{
\"username\": \"<< parameters.username >>\",
\"icon_url\": \"<< parameters.icon >>\",
\"text\": \"[${VERSION}] << parameters.message >>\"
}" >> /tmp/webhook-data.json
- run:
command: |
curl -i -H "Content-Type: application/json" -X POST -d @/tmp/webhook-data.json $MATTERMOST_RELEASE_WEBHOOK_URL_DESKTOP || echo "NOFICATION FAILED! check logs as this will succeed intentionally"
update_image:
description: "Update base image"
parameters:
apt_opts:
type: string
default: ""
steps:
- run: wget -qO - https://download.opensuse.org/repositories/Emulators:/Wine:/Debian/xUbuntu_18.04/Release.key | apt-key add -
- run: apt-get update && apt-get -y install << parameters.apt_opts >>
- run: npm ci
win_make:
description: "Run mattermost's makefile.ps1 on ./scripts/"
parameters:
operation:
type: string
default: ""
steps:
- run:
command: ./scripts/Makefile.ps1 << parameters.operation >>
name: << parameters.operation >>
shell: powershell
build:
description: "Building << parameters.os >> app"
parameters:
os:
type: string
default: "linux"
path:
type: string
default: "./dist/linux"
subpath:
type: string
default: "./linux/"
steps:
- run: npm run package:<< parameters.os >>
- run: mkdir -p << parameters.path >>
- run: bash -x ./scripts/cp_artifacts.sh release << parameters.path >>
- persist_to_workspace:
root: ./dist
paths:
- "./<< parameters.subpath >>/"
save:
description: "Save binaries artifacts"
parameters:
filename:
type: string
steps:
- run:
name: Copying artifacts
command: |
mkdir /tmp/artifacts;
cp release/<<parameters.filename>> /tmp/artifacts;
- store_artifacts:
path: /tmp/artifacts
jobs:
check:
executor: wine-chrome
steps:
- checkout
- update_image:
apt_opts: "--no-install-recommends"
- restore_cache:
key: lint-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
- run: npm run check-types
- run: ELECTRON_DISABLE_SANDBOX=1 xvfb-run npm run test
- run: mkdir -p /tmp/test-results
- run: cp test-results.xml /tmp/test-results/
- store_test_results:
path: /tmp/test-results
- save_cache:
key: lint-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- "node_modules"
build-linux:
executor: wine-mono
steps:
- checkout
- run: mkdir -p ./dist
- attach_workspace:
at: ./dist
- restore_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
- update_image:
apt_opts: "--no-install-recommends jq icnsutils graphicsmagick tzdata"
- build
- save_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- "node_modules"
- "~/.cache/electron"
- "~/.cache/electron-builder"
build-win-no-installer:
executor: wine-mono
steps:
- checkout
- run: mkdir -p ./dist
- attach_workspace:
at: ./dist
- restore_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
- update_image:
apt_opts: "--no-install-recommends jq icnsutils graphicsmagick tzdata"
- build:
os: windows
path: ./dist/win
subpath: ./win/
- save_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- "node_modules"
- "~/.cache/electron"
- "~/.cache/electron-builder"
build-mac-no-dmg:
executor: wine-mono
steps:
- checkout
- run: mkdir -p ./dist
- attach_workspace:
at: ./dist
- restore_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
- update_image:
apt_opts: "--no-install-recommends jq icnsutils graphicsmagick tzdata"
- run: jq '.mac.target=["zip"]' electron-builder.json | jq '.mac.gatekeeperAssess=false' > /tmp/electron-builder.json && cp /tmp/electron-builder.json .
- build:
os: mac
path: ./dist/macos
subpath: ./macos/
- save_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- "node_modules"
- "~/.cache/electron"
- "~/.cache/electron-builder"
msi_installer:
executor: win/vs2019
steps:
- checkout
- run: mkdir -p ./dist/
- attach_workspace:
at: ./dist
- win_make:
operation: optimize
- win_make:
operation: "install-deps"
- win_make:
operation: "build"
- run: mkdir -p ./dist/win-release
- run: cp -r release/*.zip ./dist/win-release
- run: cp -r release/*.msi ./dist/win-release
- run: cp -r release/*.exe ./dist/win-release
- persist_to_workspace:
root: ./dist/
paths:
- "./win-release/"
build-windows-pr:
executor: wine-mono
steps:
- checkout
- run: mkdir -p ./dist
- attach_workspace:
at: ./dist
- restore_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
- update_image:
apt_opts: "--no-install-recommends jq icnsutils graphicsmagick tzdata"
- build:
os: windows
path: ./dist/win
subpath: ./win/
- save_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- "node_modules"
- "~/.cache/electron"
- "~/.cache/electron-builder"
- save:
filename: "*.exe"
build-mac-pr:
executor: mac
steps:
- checkout
- run: mkdir -p ./dist
- attach_workspace:
at: ./dist
- run:
name: Update node to v16
command: brew upgrade node || true
- run:
name: Installing npm dependencies
command: npm ci
- build:
os: mac
path: ./dist/macos-release
subpath: ./macos-release/
- run:
name: Get rename without brew as it might fail
command: curl -L https://github.com/ap/rename/archive/v1.601.tar.gz --output rename.tgz
- run:
name: extract rename
command: tar -xzf rename.tgz
- run:
name: rename arm64 to m1
command: ./rename-1.601/rename 's/arm64/m1/' ./dist/macos-release/*
- persist_to_workspace:
root: ./dist
paths:
- "./macos-release/"
- save:
filename: "*.dmg"
build-linux-pr:
executor: wine-mono
steps:
- checkout
- run: mkdir -p ./dist
- attach_workspace:
at: ./dist
- restore_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
- update_image:
apt_opts: "--no-install-recommends jq icnsutils graphicsmagick tzdata"
- build
- save_cache:
key: npm-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- "node_modules"
- "~/.cache/electron"
- "~/.cache/electron-builder"
- save:
filename: "*.tar.gz"
mac_installer:
executor: mac
steps:
- checkout
- run: mkdir -p ./dist
- attach_workspace:
at: ./dist
- run:
name: Update node to v16
command: brew upgrade node || true
- run:
name: Installing npm dependencies
command: npm ci
- build:
os: mac
path: ./dist/macos-release
subpath: ./macos-release/
- run:
name: Get rename without brew as it might fail
command: curl -L https://github.com/ap/rename/archive/v1.601.tar.gz --output rename.tgz
- run:
name: extract rename
command: tar -xzf rename.tgz
- run:
name: rename arm64 to m1
command: ./rename-1.601/rename 's/arm64/m1/' ./dist/macos-release/*
- persist_to_workspace:
root: ./dist
paths:
- "./macos-release/"
store_artifacts:
executor: wine-chrome
steps:
- attach_workspace:
at: ./dist
- store_artifacts:
path: ./dist
destination: packages
- run: wget -qO - https://download.opensuse.org/repositories/Emulators:/Wine:/Debian/xUbuntu_18.04/Release.key | apt-key add -
- run: apt-get update && apt-get -y install jq
- run:
name: "store url links"
command: |
echo $(pwd)
ls .
curl -H "Circle-Token: $CIRCLE_TOKEN" -H "Accept: application/json" -X GET "https://circleci.com/api/v2/project/github/mattermost/desktop/$CIRCLE_BUILD_NUM/artifacts" | jq -r '.items[].url' >> ./dist/artifactlist.txt
grep -v ".yml" ./dist/artifactlist.txt | grep -v "\._" > ./templist.txt
echo "##### :tux: Linux" > ./dist/linklist.txt
grep "linux" ./templist.txt | awk -F/ '{print "- ["$NF"]("$0")"}' >> ./dist/linklist.txt
echo "##### :apple_logo: macOS" >> ./dist/linklist.txt
grep "macos" ./templist.txt | awk -F/ '{print "- ["$NF"]("$0")"}' >> ./dist/linklist.txt
echo "##### :windows: Windows" >> ./dist/linklist.txt
grep "win" ./templist.txt | awk -F/ '{print "- ["$NF"]("$0")"}' >> ./dist/linklist.txt
- persist_to_workspace:
root: ./dist
paths:
- ./linklist.txt
- ./artifactlist.txt
share_to_channel:
executor: wine-chrome
steps:
- attach_workspace:
at: ./dist
- run: wget -qO - https://download.opensuse.org/repositories/Emulators:/Wine:/Debian/xUbuntu_18.04/Release.key | apt-key add -
- run: apt-get update && apt-get -y install jq
- run: mkdir -p ./links
- run: echo "### Nightly builds:\n" > ./links/linklist.txt
- run:
name: "Get urls for sharing"
command: |
echo "Links for $(date +"%b-%d-%Y")" >> ./links/linklist.txt
cat ./dist/linklist.txt >> ./links/linklist.txt
- run:
command: |
linklist=$(<./links/linklist.txt);
echo '{}' | jq "{
\"username\": \"NightBuilder\",
\"icon_url\": \"https://upload.wikimedia.org/wikipedia/commons/1/17/Luna_symbol.png\",
\"text\": \"${linklist}\"
}" >> /tmp/webhook-data.json
- run:
command: |
curl -i -X POST -H "Content-Type: application/json" -d @/tmp/webhook-data.json $MM_TOKEN || echo "NOFICATION FAILED! check logs as this will succeed intentionally"
upload_to_s3:
executor: aws
steps:
- checkout
- attach_workspace:
at: ./dist
- run:
name: "Don't upload if it's not on a tag"
command: |
if [ -z `git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null` ]; then
circleci-agent step halt
fi
- run:
name: "Setup files for aws-s3"
command: |
mkdir -p ./aws-s3-dist
cp --backup=numbered ./dist/{macos-release,win-release,linux}/* ./aws-s3-dist
- aws-s3/copy:
from: ./aws-s3-dist/
to: s3://releases.mattermost.com/desktop/$(jq -r .version package.json)/
arguments: --acl public-read --cache-control "no-cache" --recursive
upload_to_s3_daily:
executor: aws
steps:
- checkout
- attach_workspace:
at: ./dist
- run:
name: "install renaming utility"
command: |
sudo apt-get install rename
- run:
name: "Normalize folder names"
command: |
mv ./dist/macos-release ./dist/macos
- run:
name: "Rename to daily for consistency"
command: |
rename 's/\d+\.\d+\.\d+/daily/' ./dist/macos/*
rename 's/\d+\.\d+\.\d+/daily/' ./dist/linux/*
rename 's/\d+\.\d+\.\d+/daily/' ./dist/win/*
- aws-s3/copy:
from: ./dist/
to: s3://mattermost-desktop-daily-builds/
arguments: --acl public-read --cache-control "no-cache" --recursive
upload_to_github:
executor: github
steps:
- checkout
- attach_workspace:
at: ./dist
- run:
name: "Don't upload if it's not on a tag"
command: |
if [ -z `git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null` ]; then
circleci-agent step halt
fi
- run:
name: "Setup files for ghr"
command: |
mkdir -p ./ghr-dist
cp --backup=numbered ./dist/{macos-release,win-release,linux}/* ./ghr-dist
- run:
name: "Publish Release on GitHub"
command: |
go get github.com/tcnksm/ghr
VERSION=$(jq -r .version package.json)
RELEASE_TITLE="v${VERSION} ($(date -u "+%Y-%m-%d"))"
ghr \
-t ${GITHUB_TOKEN} \
-u ${CIRCLE_PROJECT_USERNAME} \
-draft \
--body="$(./scripts/generate_release_markdown.sh $VERSION)" \
--name="${RELEASE_TITLE}" $( [[ $VERSION =~ "-rc" ]] && printf %s "-prerelease") \
-r ${CIRCLE_PROJECT_REPONAME} \
-c ${CIRCLE_SHA1} \
-delete \
v${VERSION} ./ghr-dist
begin-notification:
executor: wine-chrome
steps:
- checkout
- update_image:
apt_opts: "--no-install-recommends jq"
- notify:
message: "Release process for the desktop app has started, it should take about 30 minutes to complete."
end-notification:
executor: wine-chrome
steps:
- checkout
- update_image:
apt_opts: "--no-install-recommends jq"
- notify:
message: "Release process for the desktop app ended, the new release can be found on [GitHub](https://github.com/mattermost/desktop/releases)."
workflows:
version: 2
build_and_test:
jobs:
- check:
filters:
branches:
ignore:
- /^build-pr-.*/
- begin-notification:
context: desktop-notify
filters:
branches:
only:
# only for release and release candidates
# release-XX.YY.ZZ
# release-XX.YY.ZZ-rc-something
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
- build-linux:
requires:
- check
filters:
branches:
ignore:
- /^build-pr-.*/
- build-win-no-installer:
requires:
- check
filters:
branches:
ignore:
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
- /^build-pr-.*/
- build-mac-no-dmg:
requires:
- check
filters:
branches:
ignore:
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
- /^build-pr-.*/
- msi_installer:
requires:
- check
context: windows-codesign
filters:
branches:
only:
# only for release and release candidates
# release-XX.YY.ZZ
# release-XX.YY.ZZ-rc-something
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
- mac_installer:
requires:
- check
context: codesign-certificates
filters:
branches:
only:
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
- store_artifacts:
# for master/PR builds
requires:
- build-linux
- build-win-no-installer
- build-mac-no-dmg
- mac_installer
filters:
branches:
ignore:
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
- /^build-pr-.*/
- upload_to_s3:
# for release builds
requires:
- msi_installer
- mac_installer
- build-linux
context: mattermost-release-s3
filters:
branches:
only:
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
- upload_to_github:
requires:
- upload_to_s3
context: matterbuild-github-token
filters:
branches:
only:
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
- end-notification:
requires:
- upload_to_github
context: desktop-notify
filters:
branches:
only:
# only for release and release candidates
# release-XX.YY.ZZ
# release-XX.YY.ZZ-rc-something
- /^release-\d+(\.\d+){1,2}(-rc.*)?/
build-for-pr:
jobs:
- build-windows-pr:
context: electron-installer
filters:
branches:
only: /^build-pr-.*/
- build-mac-pr:
context: codesign-certificates
filters:
branches:
only: /^build-pr-.*/
- build-linux-pr:
filters:
branches:
only: /^build-pr-.*/
nightly_browser_view:
when: << pipeline.parameters.run_nightly >>
jobs:
- build-linux
- build-win-no-installer:
context: electron-installer
- mac_installer:
context: codesign-certificates
- store_artifacts:
context: desktop_browserview
# for master/PR builds
requires:
- build-linux
- build-win-no-installer
- mac_installer
- upload_to_s3_daily:
context: mattermost-desktop-daily-s3
requires:
- build-linux
- build-win-no-installer
- mac_installer
- share_to_channel:
context: desktop_browserview
requires:
- store_artifacts