55# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
66# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
77
8- name : Sample Run and Dependabot Auto-merge
8+ name : Sample Run Tests and Dependabot
99on :
1010 push :
1111 branches : [ master ]
12+ pull_request_target :
13+ branches : [ master ]
14+ types : [opened, synchronize, reopened, unlabeled]
1215
13- permissions :
14- id-token : write
15- contents : write
16- pull-requests : write
17- statuses : write
16+ concurrency :
17+ group : ruby.yml
18+ cancel-in-progress : false
1819
1920jobs :
21+ # Evaluates if the sample tests should run. If the workflow is triggered by a push OR
22+ # is triggered by a pull request without the 'skip-sample-tests' label, the sample tests should run.
23+ # Otherwise, the sample tests will be skipped
24+ check-if-should-run :
25+ runs-on : ubuntu-latest
26+ if : ${{ github.event_name == 'push' || (github.event_name == 'pull_request_target' && !contains(github.event.pull_request.labels.*.name, 'skip-sample-tests')) }}
27+ outputs :
28+ should_run : ' true'
29+ is_fork : ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.fork }}
30+ steps :
31+ - run : echo "Evaluating workflow conditions"
32+
33+ # Workflow will pause and wait here if it is triggered by a fork PR. The workflow will continue to wait until
34+ # an approved member of the environment 'manual_approval' allows the workflow to run
35+ wait-for-approval :
36+ needs : [ check-if-should-run ]
37+ if : ${{ needs.check-if-should-run.outputs.is_fork == 'true' }}
38+ runs-on : ubuntu-latest
39+ environment : manual-approval
40+ steps :
41+ - run : echo "Fork PR approved by a team member."
42+
43+ # Sample run tests of the KCL
44+ # Runs only if (check-if-should-run allows AND (the PR is not from a fork OR it has been approved to run))
2045 sample-run :
21- timeout-minutes : 8
46+ needs : [ check-if-should-run, wait-for-approval ]
47+ permissions :
48+ id-token : write
49+ if : ${{ always() && needs.check-if-should-run.outputs.should_run == 'true' && (needs.check-if-should-run.outputs.is_fork != 'true' || needs.wait-for-approval.result == 'success') }}
50+ timeout-minutes : 20
2251 runs-on : ${{ matrix.os }}
2352 defaults :
2453 run :
2554 shell : bash
2655
56+ # Initialize matrix based on PR labels (more-tests label runs more tests)
2757 strategy :
2858 fail-fast : false
2959 matrix :
30- ruby-version : [ ' 3.0', ' 3.4' ]
31- jdk-version : [ "8", "11", "17", "21", "24" ]
60+ ruby-version : ${{ github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'more-tests') && fromJSON('[" 3.0", " 3.4"]') || fromJSON('["3.0"]') }}
61+ jdk-version : ${{ github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'more-tests') && fromJSON('[ "8", "11", "17", "21", "24"]') || fromJSON('["8", "11"]') }}
3262 os : [ ubuntu-latest, macOS-latest, windows-latest ]
3363
3464 steps :
35- - name : Checkout working directory
65+ # For pull_request_target, checkout PR head instead of merge commit
66+ - name : Checkout
3667 uses : actions/checkout@v4
68+ with :
69+ ref : ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
3770
71+ # Configure AWS Credentials. Role session name is unique to avoid OIDC errors when running multiple tests concurrently
3872 - name : Configure AWS Credentials
3973 uses : aws-actions/configure-aws-credentials@v4
4074 with :
4175 aws-region : us-east-1
42- role-to-assume : arn:aws:iam::751999266872:role/GitHubRuby
43- role-session-name : myGitHubActionsRuby
76+ role-to-assume : ${{ secrets.AWS_ARN_GHA }}
77+ role-session-name : GHA-${{ github.run_id }}-${{ matrix.ruby-version }}-${{ matrix.jdk-version }}-${{ matrix.os }}
4478
4579 - name : Set up JDK ${{ matrix.jdk-version }}
4680 uses : actions/setup-java@v4
@@ -53,44 +87,82 @@ jobs:
5387 with :
5488 ruby-version : ${{ matrix.ruby-version }}
5589
56- - name : Install Bundler and run tests
90+ - name : Install dependencies and run tests
5791 run : |
58- gem install bundler
92+ gem install bundler aws-sdk-kinesis aws-kclrb
93+ if [ "${{ matrix.os }}" != "windows-latest" ]; then gem install rake; fi
5994 bundle install
6095 bundle update --bundler
6196 bundle exec rspec
6297
63- - name : Install Rake (ubuntu and macOS)
64- if : ${{ matrix.os != 'windows-latest' }}
98+ # Create unique identifiers for the stream name and application name
99+ - name : Set up unique identifiers
65100 run : |
66- gem install rake
101+ STREAM_NAME="kclrbsample-${{ matrix.os }}-rb${{ matrix.ruby-version }}-jdk${{ matrix.jdk-version }}"
102+ APP_NAME="RubyKCLSample-${{ matrix.os }}-rb${{ matrix.ruby-version }}-jdk${{ matrix.jdk-version }}"
103+ echo "STREAM_NAME=$STREAM_NAME" >> $GITHUB_ENV
104+ echo "APP_NAME=$APP_NAME" >> $GITHUB_ENV
67105
68- - name : Install Kinesis SDK
106+ # Manipulate sample.properties file to use unique stream name, application name, and OS specific program changes
107+ - name : Manipulate sample.properties file
69108 run : |
70- gem install aws-sdk-kinesis
71-
72- - name : Running KCL producer
109+ chmod +x .github/scripts/manipulate_properties.sh
110+ .github/scripts/manipulate_properties.sh
111+ env :
112+ RUNNER_OS : ${{ matrix.os }}
113+ STREAM_NAME : ${{ env.STREAM_NAME }}
114+ APP_NAME : ${{ env.APP_NAME }}
115+
116+ # Create kinesis stream with unique name and wait for it to exist
117+ - name : Create and wait Kinesis stream
73118 run : |
74- cd samples
75- rake "run_producer[10]"
119+ chmod +x .github/scripts/create_stream.sh
120+ .github/scripts/create_stream.sh
121+ env :
122+ STREAM_NAME : ${{ env.STREAM_NAME }}
76123
77- - name : Running KCL consumer (windows or ubuntu)
78- if : ${{ matrix.os != 'macOS-latest'}}
124+ # Put words to sample stream with unique name based on run ID
125+ - name : Put words to sample stream
79126 run : |
80- cd samples
81- timeout 45 rake run properties_file=sample.properties || status="$?"; if (( status == 124 )); then exit 0; else exit 1; fi; exit "$status"
127+ chmod +x .github/scripts/put_words_to_stream.sh
128+ .github/scripts/put_words_to_stream.sh
129+ env :
130+ STREAM_NAME : ${{ env.STREAM_NAME }}
82131
83- - name : Running KCL consumer (macOS)
84- if : ${{ matrix.os == 'macOS-latest'}}
132+ # Run sample KCL application
133+ - name : Start KCL application
134+ run : |
135+ chmod +x .github/scripts/start_kcl.sh
136+ .github/scripts/start_kcl.sh
137+ env :
138+ RUNNER_OS : ${{ matrix.os }}
139+ STREAM_NAME : ${{ env.STREAM_NAME }}
140+
141+ # Check and verify results of KCL test
142+ - name : Verify KCL Functionality
85143 run : |
86- brew install coreutils
87- cd samples
88- gtimeout 45 rake run properties_file=sample.properties || status="$?"; if (( status == 124 )); then exit 0; else exit 1; fi; exit "$status"
144+ chmod +x .github/scripts/verify_kcl.sh
145+ .github/scripts/verify_kcl.sh
146+ env :
147+ APP_NAME : ${{ env.APP_NAME }}
148+
149+ # Clean up all existing Streams and DDB tables
150+ - name : Clean up Kinesis Stream and DynamoDB table
151+ if : always()
152+ run : |
153+ chmod +x .github/scripts/clean_up_stream_table.sh
154+ .github/scripts/clean_up_stream_table.sh
155+ env :
156+ STREAM_NAME : ${{ env.STREAM_NAME }}
157+ APP_NAME : ${{ env.APP_NAME }}
89158
90159 auto-merge-dependabot :
91160 needs : [sample-run]
92161 runs-on : ubuntu-latest
93162 if : github.actor == 'dependabot[bot]' && github.event.pull_request.user.login == 'dependabot[bot]'
163+ permissions :
164+ contents : read
165+ pull-requests : write
94166 steps :
95167 - name : Fetch Dependabot metadata
96168 id : metadata
@@ -99,12 +171,12 @@ jobs:
99171 alert-lookup : true
100172 github-token : " ${{ secrets.GITHUB_TOKEN }}"
101173
102- # - name: Approve PR
103- # if: steps.metadata.outputs.update-type != 'version-update:semver-major'
104- # run: gh pr review --approve "$PR_URL"
105- # env:
106- # PR_URL: ${{github.event.pull_request.html_url}}
107- # GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
174+ - name : Approve PR
175+ if : steps.metadata.outputs.update-type != 'version-update:semver-major'
176+ run : gh pr review --approve "$PR_URL"
177+ env :
178+ PR_URL : ${{github.event.pull_request.html_url}}
179+ GH_TOKEN : ${{secrets.GITHUB_TOKEN}}
108180
109181# - name: Enable auto-merge for Dependabot PRs
110182# if: steps.metadata.outputs.update-type != 'version-update:semver-major'
0 commit comments