Skip to content

Commit 4f58518

Browse files
authored
fix cicd to support forked repo (#145)
* fix cicd to support forked repo * added support for pr label checks
1 parent 53a78a0 commit 4f58518

File tree

2 files changed

+65
-33
lines changed

2 files changed

+65
-33
lines changed

.github/workflows/pull_request_lint.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Pull Request Lint
22

33
on:
44
pull_request:
5-
types: ['opened', 'edited', 'reopened', 'synchronize']
5+
types: ['opened', 'edited', 'reopened', 'synchronize', 'labeled', 'unlabeled']
66

77
jobs:
88
title:
@@ -19,3 +19,14 @@ jobs:
1919
titleRegex: '^#(?<ticketNumber>\d+)'
2020
bodyRegex: '#(?<ticketNumber>\d+)'
2121
bodyURLRegex: 'http(s?):\/\/(github.com)(\/LambdaTest)(\/test-at-scale)(\/issues)\/(?<ticketNumber>\d+)'
22+
23+
label-checker:
24+
name: pr label check
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: PR Label Check
29+
uses: yashhy/pr-label-check-and-comment-action@master
30+
with:
31+
required_labels: 'release:minor, release:major, release:patch'
32+
GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}'

.github/workflows/release.yml

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,76 @@
11
name: Release on Dev
22

33
on:
4-
pull_request:
5-
types:
6-
- closed
4+
push:
75
branches:
86
- main
97

108
jobs:
119

1210
Release:
1311

14-
if: github.event.pull_request.merged == true
1512
runs-on: ubuntu-latest
16-
strategy:
17-
matrix:
18-
label: ${{ github.event.pull_request.labels.*.name }}
1913

2014
steps:
2115

22-
- if: startsWith(matrix.label, 'release:')
23-
name: Retrieving Release Type
16+
- name: Check Patch Label
17+
id: check_pr_labels_patch
18+
uses: shioyang/check-pr-labels-on-push-action@v1.0.3
19+
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
labels: '["release:patch"]'
22+
23+
- name: Check Minor Label
24+
id: check_pr_labels_minor
25+
uses: shioyang/check-pr-labels-on-push-action@v1.0.3
26+
with:
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
labels: '["release:minor"]'
29+
30+
- name: Check Major Label
31+
id: check_pr_labels_major
32+
uses: shioyang/check-pr-labels-on-push-action@v1.0.3
33+
with:
34+
github-token: ${{ secrets.GITHUB_TOKEN }}
35+
labels: '["release:major"]'
36+
37+
- name: Release Type
2438
run: |
25-
release_type=`echo ${{matrix.label}} | awk -F':' '{print $NF}'`
26-
echo "RELEASE_TYPE=${release_type}" >> $GITHUB_ENV
27-
echo "Releasing: ${release_type}"
39+
if [ ${MAJOR} == "true" ] ; then
40+
echo "RELEASE_TYPE=major" >> $GITHUB_ENV
41+
elif [ ${MINOR} == "true" ] ; then
42+
echo "RELEASE_TYPE=minor" >> $GITHUB_ENV
43+
elif [ ${PATCH} == "true" ] ; then
44+
echo "RELEASE_TYPE=patch" >> $GITHUB_ENV
45+
else
46+
echo "RELEASE_TYPE=none" >> $GITHUB_ENV
47+
fi
48+
env:
49+
PATCH: ${{ steps.check_pr_labels_patch.outputs.result }}
50+
MINOR: ${{ steps.check_pr_labels_minor.outputs.result }}
51+
MAJOR: ${{ steps.check_pr_labels_major.outputs.result }}
52+
53+
- name: Testing Release Type
54+
if: env.RELEASE_TYPE == 'none'
55+
uses: actions/github-script@v3
56+
with:
57+
script: |
58+
core.setFailed('Release labels were not present in the PR!')
2859
29-
- if: startsWith(matrix.label, 'release:')
30-
name: Inject slug/short variables
60+
- name: Inject slug/short variables
3161
uses: rlespinasse/github-slug-action@v3.x
3262

33-
- if: startsWith(matrix.label, 'release:')
34-
name: Checkout
63+
- name: Checkout
3564
uses: actions/checkout@v2.4.0
3665

37-
- if: startsWith(matrix.label, 'release:')
38-
name: Bump version and push tag
66+
- name: Bump version and push tag
3967
id: tag_version
4068
uses: mathieudutour/github-tag-action@v6.0
4169
with:
4270
github_token: ${{ secrets.GITHUB_TOKEN }}
4371
default_bump: ${{ env.RELEASE_TYPE }}
4472

45-
- if: startsWith(matrix.label, 'release:')
46-
name: Creating Github Release
73+
- name: Creating Github Release
4774
uses: ncipollo/release-action@v1
4875
with:
4976
token: ${{ secrets.GITHUB_TOKEN }}
@@ -54,43 +81,37 @@ jobs:
5481
name: Release ${{ steps.tag_version.outputs.new_tag }}
5582
body: ${{ steps.changelog.outputs.changelog }}
5683

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

64-
- if: startsWith(matrix.label, 'release:')
65-
name: Setup Environment
90+
- name: Setup Environment
6691
run: |
6792
echo "BOTNAME=Test-at-Scale Deployment Status: Version ${{ steps.tag_version.outputs.new_tag }} to dev" >> $GITHUB_ENV
6893
69-
- if: startsWith(matrix.label, 'release:')
70-
name: Setup Docker Image Tags
94+
- name: Setup Docker Image Tags
7195
run: |
7296
echo "NUCLEUS_TAGS=lambdatest/nucleus:dev-base","lambdatest/nucleus:${{ steps.tag_version.outputs.new_tag }}-base" >> $GITHUB_ENV
7397
echo "SYNAPSE_TAGS=lambdatest/synapse:dev","lambdatest/synapse:${{ steps.tag_version.outputs.new_tag }}" >> $GITHUB_ENV
7498
75-
- if: startsWith(matrix.label, 'release:')
76-
name: Docker Login
99+
- name: Docker Login
77100
uses: docker/login-action@v1.13.0
78101
with:
79102
username: ${{ secrets.DOCKER_USERNAME }}
80103
password: ${{ secrets.DOCKER_TOKEN }}
81104
logout: true
82105

83-
- if: startsWith(matrix.label, 'release:')
84-
name: Build and push Nucleus images
106+
- name: Build and push Nucleus images
85107
uses: docker/build-push-action@v2.9.0
86108
with:
87109
context: .
88110
tags: ${{ env.NUCLEUS_TAGS }}
89111
file: build/nucleus/Dockerfile
90112
push: true
91113

92-
- if: startsWith(matrix.label, 'release:')
93-
name: Build and push Synapse images
114+
- name: Build and push Synapse images
94115
uses: docker/build-push-action@v2.9.0
95116
with:
96117
context: .

0 commit comments

Comments
 (0)