Skip to content

Commit

Permalink
fix cicd to support forked repo (#145)
Browse files Browse the repository at this point in the history
* fix cicd to support forked repo

* added support for pr label checks
  • Loading branch information
nevilm-lt authored Apr 26, 2022
1 parent 53a78a0 commit 4f58518
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 33 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/pull_request_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Pull Request Lint

on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']
types: ['opened', 'edited', 'reopened', 'synchronize', 'labeled', 'unlabeled']

jobs:
title:
Expand All @@ -19,3 +19,14 @@ jobs:
titleRegex: '^#(?<ticketNumber>\d+)'
bodyRegex: '#(?<ticketNumber>\d+)'
bodyURLRegex: 'http(s?):\/\/(github.com)(\/LambdaTest)(\/test-at-scale)(\/issues)\/(?<ticketNumber>\d+)'

label-checker:
name: pr label check
runs-on: ubuntu-latest

steps:
- name: PR Label Check
uses: yashhy/pr-label-check-and-comment-action@master
with:
required_labels: 'release:minor, release:major, release:patch'
GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}'
85 changes: 53 additions & 32 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,76 @@
name: Release on Dev

on:
pull_request:
types:
- closed
push:
branches:
- main

jobs:

Release:

if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
strategy:
matrix:
label: ${{ github.event.pull_request.labels.*.name }}

steps:

- if: startsWith(matrix.label, 'release:')
name: Retrieving Release Type
- name: Check Patch Label
id: check_pr_labels_patch
uses: shioyang/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["release:patch"]'

- name: Check Minor Label
id: check_pr_labels_minor
uses: shioyang/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["release:minor"]'

- name: Check Major Label
id: check_pr_labels_major
uses: shioyang/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
labels: '["release:major"]'

- name: Release Type
run: |
release_type=`echo ${{matrix.label}} | awk -F':' '{print $NF}'`
echo "RELEASE_TYPE=${release_type}" >> $GITHUB_ENV
echo "Releasing: ${release_type}"
if [ ${MAJOR} == "true" ] ; then
echo "RELEASE_TYPE=major" >> $GITHUB_ENV
elif [ ${MINOR} == "true" ] ; then
echo "RELEASE_TYPE=minor" >> $GITHUB_ENV
elif [ ${PATCH} == "true" ] ; then
echo "RELEASE_TYPE=patch" >> $GITHUB_ENV
else
echo "RELEASE_TYPE=none" >> $GITHUB_ENV
fi
env:
PATCH: ${{ steps.check_pr_labels_patch.outputs.result }}
MINOR: ${{ steps.check_pr_labels_minor.outputs.result }}
MAJOR: ${{ steps.check_pr_labels_major.outputs.result }}

- name: Testing Release Type
if: env.RELEASE_TYPE == 'none'
uses: actions/github-script@v3
with:
script: |
core.setFailed('Release labels were not present in the PR!')
- if: startsWith(matrix.label, 'release:')
name: Inject slug/short variables
- name: Inject slug/short variables
uses: rlespinasse/[email protected]

- if: startsWith(matrix.label, 'release:')
name: Checkout
- name: Checkout
uses: actions/[email protected]

- if: startsWith(matrix.label, 'release:')
name: Bump version and push tag
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: ${{ env.RELEASE_TYPE }}

- if: startsWith(matrix.label, 'release:')
name: Creating Github Release
- name: Creating Github Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -54,43 +81,37 @@ jobs:
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.changelog.outputs.changelog }}

- if: startsWith(matrix.label, 'release:')
name: Build Cloud Runners
- name: Build Cloud Runners
run: |
gh workflow run -R ${{ secrets.WF_REPO }} ${{ secrets.WF_NAME }} -r main -f environment=dev -f version=${{ steps.tag_version.outputs.new_tag }}
env:
GITHUB_TOKEN: ${{secrets.GH_API_TOKEN}}

- if: startsWith(matrix.label, 'release:')
name: Setup Environment
- name: Setup Environment
run: |
echo "BOTNAME=Test-at-Scale Deployment Status: Version ${{ steps.tag_version.outputs.new_tag }} to dev" >> $GITHUB_ENV
- if: startsWith(matrix.label, 'release:')
name: Setup Docker Image Tags
- name: Setup Docker Image Tags
run: |
echo "NUCLEUS_TAGS=lambdatest/nucleus:dev-base","lambdatest/nucleus:${{ steps.tag_version.outputs.new_tag }}-base" >> $GITHUB_ENV
echo "SYNAPSE_TAGS=lambdatest/synapse:dev","lambdatest/synapse:${{ steps.tag_version.outputs.new_tag }}" >> $GITHUB_ENV
- if: startsWith(matrix.label, 'release:')
name: Docker Login
- name: Docker Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
logout: true

- if: startsWith(matrix.label, 'release:')
name: Build and push Nucleus images
- name: Build and push Nucleus images
uses: docker/[email protected]
with:
context: .
tags: ${{ env.NUCLEUS_TAGS }}
file: build/nucleus/Dockerfile
push: true

- if: startsWith(matrix.label, 'release:')
name: Build and push Synapse images
- name: Build and push Synapse images
uses: docker/[email protected]
with:
context: .
Expand Down

0 comments on commit 4f58518

Please sign in to comment.