Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/actions/release-rules/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release Rules Checker
description: Determines release type based on the git ref and provided rules

inputs:
release_tag_regex:
required: false
description: 'Regex to match the git tag to determine if this a release run of the workflow'
default: 'v[0-9]+(\.[0-9]+){0,2}'
prerelease_tag_regex:
required: false
description: 'Regex to match the git tag to determine if this a pre-release run of the workflow'
default: 'v[0-9]+(\.[0-9]+){0,2}(-([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?'
prefix:
required: false
description: "(Optional) prefix of git tags to use. Example: 'sdk/'"
default: ''
outputs:
release-type:
description: 'Type of the release. One of: [dev, pre-release, release]'
value: ${{ steps.tag-check.outputs.release-type }}

runs:
using: composite
steps:
- run: |
release_regex='^refs/tags/${{ inputs.prefix }}${{ inputs.release_tag_regex }}$'
prerelease_regex='^refs/tags/${{ inputs.prefix }}${{ inputs.prerelease_tag_regex }}$'
if [[ '${{ github.event.ref }}' =~ ${release_regex} ]]; then
echo '::set-output name=release-type::release'
elif [[ '${{ github.event.ref }}' =~ ${prerelease_regex} ]]; then
echo '::set-output name=release-type::pre-release'
else
echo '::set-output name=release-type::dev'
fi
id: tag-check
shell: bash
35 changes: 35 additions & 0 deletions .github/workflows/helm-chart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: helm-chart

on:
push:
paths:
- ".github/workflows/helm-chart.yml"
- "infra/charts/**"
branches:
- main
workflow_dispatch:
inputs:
owner:
description: The GitHub user or org that owns this repository
type: string
required: true
repository:
description: The GitHub repository
type: string
required: true
default: "charts"

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run chart-releaser
uses: stefanprodan/helm-gh-pages@v1.4.1
with:
token: "${{ secrets.GH_PAGES_TOKEN }}"
charts_dir: infra/charts
owner: "${{ github.event.inputs.owner || 'turing-ml' }}"
repository: "${{ github.event.inputs.repository || 'charts' }}"
commit_username: ${{ github.actor }}
commit_email: "${{ github.actor }}@users.noreply.github.com"
210 changes: 210 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
name: XP Release

on:
workflow_call:
inputs:
container_registry:
type: string
required: false
default: ghcr.io
environment:
type: string
required: false
secrets:
ghcr_token:
required: true

env:
ARTIFACT_RETENTION_DAYS: 7

jobs:
build-ui:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ui
steps:
- name: Checkout to the target branch
uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 14

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache YARN
uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install
run: yarn install --network-concurrency 1

- name: Lint code
run: yarn lint

- name: Build UI
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: yarn build

- name: Publish Artifact
uses: actions/upload-artifact@v3
with:
name: xp-ui-dist
path: ui/build/
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

build-management-service:
runs-on: ubuntu-latest
env:
APP_NAME: xp-management
needs:
- build-ui
outputs:
api-version: ${{ steps.build-image.outputs.api-version }}
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Download UI Dist
uses: actions/download-artifact@v2
with:
name: xp-ui-dist
path: ui/build

- name: Download Management Service binary
uses: actions/download-artifact@v2
with:
name: management-service-binary
path: management-service/bin/

- name: Sync vendor directory
working-directory: management-service
run: |
echo "Fetching dependencies..."
go mod vendor

- name: Build Docker image
id: build-image
run: |
set -o pipefail
make BIN_NAME=$APP_NAME build-image | tee output.log
echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)"

- name: Save Docker image
run: |
docker image save \
--output xp-management.${{ steps.build-image.outputs.api-version }}.tar \
xp-management:${{ steps.build-image.outputs.api-version }}

- name: Publish Artifact
uses: actions/upload-artifact@v3
with:
name: xp-management.${{ steps.build-image.outputs.api-version }}.tar
path: xp-management.${{ steps.build-image.outputs.api-version }}.tar
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

build-treatment-service:
runs-on: ubuntu-latest
env:
APP_NAME: xp-treatment
outputs:
api-version: ${{ steps.build-image.outputs.api-version }}
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Download Treatment Service binary
uses: actions/download-artifact@v2
with:
name: treatment-service-binary
path: treatment-service/bin/

- name: Build Docker image
id: build-image
working-directory: treatment-service
run: |
set -o pipefail
make BIN_NAME=$APP_NAME build-image | tee output.log
echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)"

- name: Save Docker image
run: |
docker image save \
--output xp-treatment.${{ steps.build-image.outputs.api-version }}.tar \
xp-treatment:${{ steps.build-image.outputs.api-version }}

- name: Publish Artifact
uses: actions/upload-artifact@v3
with:
name: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar
path: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

publish-management-service:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
needs:
- build-management-service
steps:
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ inputs.container_registry }}
username: ${{ github.actor }}
password: ${{ secrets.ghcr_token }}

- name: Download Docker image tar
uses: actions/download-artifact@v2
with:
name: xp-management.${{ needs.build-management-service.outputs.api-version }}.tar

- name: Publish Docker Image
env:
DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }}
run: |
docker image load --input xp-management.${{ needs.build-management-service.outputs.api-version }}.tar
docker tag \
xp-management:${{ needs.build-management-service.outputs.api-version }} \
${{ env.DOCKER_REPOSITORY }}/xp-management:${{ needs.build-management-service.outputs.api-version }}
docker push ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ needs.build-management-service.outputs.api-version }}

publish-treatment-service:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
needs:
- build-treatment-service
steps:
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ inputs.container_registry }}
username: ${{ github.actor }}
password: ${{ secrets.ghcr_token }}

- name: Download Docker image tar
uses: actions/download-artifact@v2
with:
name: xp-treatment.${{ needs.build-treatment-service.outputs.api-version }}.tar

- name: Publish Docker Image
env:
DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }}
run: |
docker image load --input xp-treatment.${{ needs.build-treatment-service.outputs.api-version }}.tar
docker tag \
xp-treatment:${{ needs.build-treatment-service.outputs.api-version }} \
${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ needs.build-treatment-service.outputs.api-version }}
docker push ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ needs.build-treatment-service.outputs.api-version }}
73 changes: 64 additions & 9 deletions .github/workflows/tests.yml → .github/workflows/xp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ on:
pull_request:
branches:
- main

# To make it possible to trigger e2e CI workflow for any arbitrary git ref
workflow_dispatch:

env:
ARTIFACT_RETENTION_DAYS: 7

jobs:
lint-python:
Expand All @@ -35,32 +41,33 @@ jobs:
lint-go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Go
id: setup-go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: "1.16"
go-version: 1.16
- uses: actions/checkout@v3
- name: Lint Common module
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.41.1
working-directory: common
skip-go-installation: true
args: --timeout 3m --verbose
- name: Lint Management Service module
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.41.1
working-directory: management-service
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: true
args: --timeout 3m --verbose
- name: Lint Treatment Service module
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.41.1
working-directory: treatment-service
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: true
args: --timeout 3m --verbose

unit-tests-management:
Expand Down Expand Up @@ -173,10 +180,58 @@ jobs:
- name: Build binaries
run: make build

- name: Publish Management Service Artifact
uses: actions/upload-artifact@v3
with:
name: management-service-binary
path: management-service/bin/
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

- name: Publish Treatment Service Artifact
uses: actions/upload-artifact@v3
with:
name: treatment-service-binary
path: treatment-service/bin/
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

- name: Run E2E tests
env:
DATABASE_HOST: localhost
DATABASE_NAME: xp
DATABASE_USER: xp
DATABASE_PASSWORD: xp
run: make e2e-ci

release-rules:
runs-on: ubuntu-latest
outputs:
release-type: ${{ steps.release-rules.outputs.release-type }}
steps:
- uses: actions/checkout@v2
- id: release-rules
uses: ./.github/actions/release-rules

# release:
# # Automatically publish release and pre-release artifacts.
# #
# # As for dev releases, make it possible to publish artifacts
# # manually by approving 'deployment' in the 'manual' environment.
# #
# # Dev build can be released either from the 'main' branch or
# # by running this workflow manually with `workflow_dispatch` event.
# if: >-
# contains('release,pre-release', needs.release-rules.outputs.release-type)
# || ( github.event_name != 'pull_request' )
# || ( github.event.pull_request.head.repo.full_name == github.repository )
# needs:
# - lint-python
# - lint-go
# - unit-tests-management
# - unit-tests-treatment
# - e2e-tests
# - release-rules
# uses: gojek/xp/.github/workflows/release.yml@main
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To uncomment release action in subsequent PR.

# with:
# environment: ${{ needs.release-rules.outputs.release-type == 'dev' && 'manual' || '' }}
# secrets:
# ghcr_token: ${{ secrets.GITHUB_TOKEN }}
Loading