Skip to content

Commit

Permalink
chore: merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tlebon committed Dec 19, 2023
2 parents 6164354 + 0d0ca5b commit 9e201f8
Show file tree
Hide file tree
Showing 49 changed files with 1,101 additions and 524 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on:
pull_request:
# we want to run the CI on every PR targetting those branches
branches: [master, dev]

push:
# We also run CI on dev in order to update the coverage monitoring
branches: [dev]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: buildjet-8vcpu-ubuntu-2204

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 16.x
cache: 'yarn'

- name: Install JS dependencies
run: yarn --immutable

- name: Lint
run: yarn lint

- name: Test
run: yarn test --coverage --coverage-reporters=lcov --detectOpenHandles=false

- name: Monitor coverage
uses: codecov/[email protected]
with:
fail_ci_if_error: false
files: ./coverage/lcov.info
flags: unittests
31 changes: 0 additions & 31 deletions .github/workflows/lint.yml

This file was deleted.

204 changes: 181 additions & 23 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
name: Publish Docker image, Helm chart and Wire build
name: Publish

on:
push:
branches: [master, dev, edge]
branches: [master, dev]
tags:
- '*staging*'
- '*production*'

concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build Docker image and Helm Chart
Expand All @@ -14,16 +20,18 @@ jobs:
image_tag: ${{ steps.push_docker_image.outputs.image_tag }}
release_name: ${{ steps.push_docker_image.outputs.release_name }}
chart_version: ${{ steps.publish_helm_chart.outputs.chart_version }}
changelog: ${{ steps.generate_changelog.outputs.changelog }}
unit_tests_report: ${{ env.UNIT_TEST_REPORT_FILE }}
build_artifact: ${{ env.BUILD_ARTIFACT }}

env:
TEST_COVERAGE_FAIL_THRESHOLD: 45
TEST_COVERAGE_WARNING_THRESHOLD: 60
BUILD_ARTIFACT: server/dist/s3/ebs.zip
COMMIT_URL: ${{github.event.head_commit.url}}
COMMITTER: ${{github.event.head_commit.committer.name}}
CHANGELOG_FILE: './changelog.md'
UNIT_TEST_REPORT_FILE: './unit-tests.log'

steps:
- uses: azure/setup-helm@v3
with:
version: '3.12.2'
id: install
- name: Checkout
uses: actions/checkout@v4
with:
Expand All @@ -37,25 +45,13 @@ jobs:
run: |
echo "BRANCH_NAME=$(git branch --show-current)" >> $GITHUB_ENV
echo "TAG=$(git tag --points-at ${{github.sha}})" >> $GITHUB_ENV
echo "PR_LAST_COMMIT_MESSAGE=$(git log --format=%B -n 1 ${{github.event.after}} | head -n 1)" >> $GITHUB_ENV
- name: Set TITLE
env:
PR_TITLE: ${{github.event.pull_request.title || env.PR_LAST_COMMIT_MESSAGE}}
run: |
echo "TITLE=${PR_TITLE}" >> $GITHUB_ENV
- name: Print environment variables
run: |
echo -e "BRANCH_NAME = ${BRANCH_NAME}"
echo -e "TAG = ${TAG}"
echo -e "TITLE = ${TITLE}"
echo -e "PR_LAST_COMMIT_MESSAGE = ${PR_LAST_COMMIT_MESSAGE}"
echo -e "COMMIT_URL = ${COMMIT_URL}"
echo -e "COMMITTER = ${COMMITTER}"
- name: Skip CI
if: |
contains(env.TITLE || env.PR_LAST_COMMIT_MESSAGE, 'skip ci') ||
contains(env.TITLE || env.PR_LAST_COMMIT_MESSAGE, '[ci skip]')
uses: andymckay/[email protected]
- name: Define target branches in wireapp/wire-builds to bump
id: output_target_branches
shell: bash
Expand All @@ -78,14 +74,56 @@ jobs:
echo "wire_builds_target_branches: $wire_builds_target_branches"
echo "wire_builds_target_branches=$wire_builds_target_branches" >> $GITHUB_OUTPUT
- name: Install JS dependencies
run: yarn --immutable

- name: Test
run: |
set -o pipefail
yarn test --coverage --coverage-reporters=lcov --detectOpenHandles=false 2>&1 | tee ./unit-tests.log
yarn test --detectOpenHandles=false 2>&1 | tee ${{ env.UNIT_TEST_REPORT_FILE }}
- uses: actions/upload-artifact@v4
with:
name: 'unit-tests-report'
path: ${{env.UNIT_TEST_REPORT_FILE}}

- name: Build
run: yarn build:prod

- uses: actions/upload-artifact@v4
with:
name: 'build-artifact'
path: ${{env.BUILD_ARTIFACT}}

- uses: kanga333/variable-mapper@master
id: changelog
with:
key: '${{github.ref}}'
map: |
{
"production": {
"changelog_type": "production"
},
"staging": {
"changelog_type": "staging"
}
}
export_to: env

- name: Generate changelog
id: generate_changelog
if: ${{ env.changelog_type }}
run: |
yarn changelog:${{ env.changelog_type }} > ${{ env.CHANGELOG_FILE }}
echo "changelog=${{ env.CHANGELOG_FILE }}" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
if: ${{ env.changelog_type }}
with:
name: 'changelog'
path: ${{ env.CHANGELOG_FILE }}

- name: Push Docker image
id: push_docker_image
env:
Expand All @@ -102,6 +140,12 @@ jobs:
packageVersion=$(cat ./package.json | jq -r '.version')
release_name="${TAG:-v${packageVersion}}"
echo "release_name=$release_name" >> $GITHUB_OUTPUT
- uses: azure/setup-helm@v3
with:
version: '3.12.2'
id: install

- name: Publish Helm chart
shell: bash
id: publish_helm_chart
Expand Down Expand Up @@ -162,7 +206,8 @@ jobs:
git commit -m "Bump webapp to $chart_version"
git push origin "${{ matrix.target_branch }}"
# FUTUREWORK: Remove this job once production builds are based on wireapp/wire-builds
#FUTUREWORK: Remove this job once production builds are based on wireapp/wire-builds
update_helm_chart:
name: 'Create PR in wire-server: Bump Helm chart'
runs-on: ubuntu-latest
Expand Down Expand Up @@ -213,3 +258,116 @@ jobs:
shell: bash
run: |
echo "PR: ${{ steps.create-pr.outputs.pull-request-url }}"
set_deployment_targets:
name: 'Set deployment targets'
runs-on: ubuntu-latest
needs: build
outputs:
deployment_targets: ${{env.targets}}

steps:
# generates a mapping between branches/tag to aws envs to deploy to
- uses: kanga333/variable-mapper@master
id: targets
with:
key: '${{github.ref}}'
map: |
{
"dev": {
"targets": "[\"wire-webapp-dev-al2\", \"wire-webapp-edge-al2\" ]"
},
"master": {
"targets": "[\"wire-webapp-master-al2\"]"
},
"production": {
"targets": "[\"wire-webapp-prod-al2\"]"
},
"staging": {
"targets": "[\"wire-webapp-staging-al2\"]"
}
}
export_to: env

deploy_to_aws:
name: 'Deploy to live environments'
runs-on: ubuntu-latest
needs: [build, set_deployment_targets]

strategy:
matrix:
target: ${{fromJson(needs.set_deployment_targets.outputs.deployment_targets)}}

steps:
- name: Set tag
run: |
echo "TAG=$(git tag --points-at ${{github.sha}})" >> $GITHUB_ENV
- uses: actions/download-artifact@v4
with:
name: 'build-artifact'

- name: Deploy to ${{matrix.target}}
if: false
uses: einaregilsson/beanstalk-deploy@v21
with:
application_name: Webapp
aws_access_key: ${{secrets.WEBTEAM_AWS_ACCESS_KEY_ID}}
aws_secret_key: ${{secrets.WEBTEAM_AWS_SECRET_ACCESS_KEY}}
deployment_package: ${{needs.build.outputs.build_artifact}}
environment_name: ${{matrix.target}}
region: eu-central-1
use_existing_version_if_available: true
version_description: ${{github.sha}}
version_label: ${{github.run_id}}
wait_for_deployment: false
wait_for_environment_recovery: 150

create_gh_release:
name: 'Create Github release'
runs-on: ubuntu-latest
needs: [deploy_to_aws, build]

outputs:
release_url: ${{ steps.release.outputs.url }}

steps:
- name: Set tag
run: |
echo "TAG=$(git tag --points-at ${{github.sha}})" >> $GITHUB_ENV
- uses: actions/download-artifact@v4
with:
name: 'changelog'

- uses: actions/download-artifact@v4
with:
name: 'unit-tests-report'

- name: Create GitHub release
if: ${{env.TAG}}
id: 'release'
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{github.token}}
with:
tag_name: ${{env.TAG}}
body_path: ${{ needs.build.outputs.changelog }}
files: ${{ needs.build.outputs.unit_tests_report }}
draft: true
prerelease: ${{contains(env.TAG, 'staging')}}

announce_deployment:
name: 'Announce deployment to wire chats'
runs-on: ubuntu-latest
needs: create_gh_release

steps:
- name: Announce staging release
if: ${{ needs.create_gh_release.outputs.release_url }}
uses: wireapp/[email protected]
with:
email: ${{secrets.WIRE_BOT_EMAIL}}
password: ${{secrets.WIRE_BOT_PASSWORD}}
conversation: '697c93e8-0b13-4204-a35e-59270462366a'
send_text: 'New release done ([full changelog](${{ needs.create_gh_release.outputs.release_url }})) 🚀'
8 changes: 1 addition & 7 deletions bin/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import fs from 'fs-extra';
import Changelog from 'generate-changelog';
import path from 'path';
import simpleGit from 'simple-git';
import * as pkg from '../package.json';

Expand All @@ -22,7 +20,6 @@ const until = args[1];
*/
void (async () => {
const tags = await simpleGit().tags({'--list': null});
const outputPath = path.join(__dirname, '../CHANGELOG.md');
const productionTags = tags.all.filter(tag => tag.includes(`-${releaseType}.`));

const newProductionTag = productionTags.sort().reverse()[0];
Expand All @@ -31,16 +28,13 @@ void (async () => {
const from = until ? newProductionTag : lastProductionTag;
const to = until ? until : newProductionTag;

console.info(`Generating changelog with commits from "${from}" to "${to}".`);

try {
const changelog = await Changelog.generate({
exclude: ['chore', 'docs', 'refactor', 'style', 'test', 'runfix'],
repoUrl: pkg.repository.url.replace('.git', ''),
tag: `${from}...${to}`,
});
fs.outputFileSync(outputPath, changelog, 'utf8');
console.info(`Wrote file to: ${outputPath}`);
console.log(changelog);
} catch (error: any) {
console.warn(`Could not generate changelog from "${from}" to "${to}": ${error.message}`, error);
}
Expand Down
Loading

0 comments on commit 9e201f8

Please sign in to comment.