danger-dangermattic 1.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71795650c10fd356f78fc2869d6b7bf2b00ccd7869e2d028f96d8544d08f36af
4
- data.tar.gz: a977dc6bd64a8bc05c5c2ef5260ae38f72f89e4c982261676895ce1ce2bcc1ec
3
+ metadata.gz: b15ae97cc1a24568ecab35470fabcf26fcb858e586abf81f1c9cba4e8f28a095
4
+ data.tar.gz: 5a5441a1ffd66d05a136e3db188b3f20cb963ef8c376ea70af86b6194cf6a79c
5
5
  SHA512:
6
- metadata.gz: 59c20e0c9156972b46ec07ce038805619fbd55f0772dd270820860ab221f4ef2f1e35fad58dd8f8e27e28d70e2b83eeff700983415a49b75337932b7f2923aa9
7
- data.tar.gz: 432b33e4ad2e9ebc7ac7ad03476d4f07ded20456ea57ffb6554184d162d2acbfedcf0b703e50330de6629de33274b161e19c3d6006ae4cfad5dc0b6e47755d2e
6
+ metadata.gz: b5fe63d7356f08bd84721b91436eb66e66e6a3b1cb4b53c17e5e503e10d95417af516224c904dd788c5971b5e69d79e09e1d11c0a87673051a2bd34deb6add6a
7
+ data.tar.gz: 03c6f7e8fe657924e88aeaecd6d0bf56ae68f133f3b5ed0214267507ab1c4692f711b181a5ec41e2de47bb12e13da4e2af7d6cb0a1155d6ad628a2abf7f74a6d
@@ -0,0 +1,124 @@
1
+ on:
2
+ workflow_call:
3
+ inputs:
4
+ org-slug:
5
+ description: 'Buildkite organization slug'
6
+ required: true
7
+ type: string
8
+ pipeline-slug:
9
+ description: 'Slug of the Buildkite pipeline to be run'
10
+ required: true
11
+ type: string
12
+ retry-step-key:
13
+ description: 'Key of the Buildkite job to be retried'
14
+ required: true
15
+ type: string
16
+ build-commit-sha:
17
+ description: 'Commit to check for running Buildkite Builds on. Usually github.event.pull_request.head.sha .'
18
+ required: true
19
+ type: string
20
+ cancel-running-github-jobs:
21
+ description: 'Cancel currently in progress Github jobs when new ones are added.'
22
+ default: true
23
+ type: boolean
24
+ required: false
25
+ secrets:
26
+ buildkite-api-token:
27
+ required: true
28
+
29
+ concurrency:
30
+ group: danger-buildkite-retry-${{ github.ref }}
31
+ cancel-in-progress: ${{ inputs.cancel-running-github-jobs }}
32
+
33
+ jobs:
34
+ retry-buildkite-job:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - name: "🔄 Retry job on the latest Buildkite Build"
38
+ run: |
39
+ ORG_SLUG="${{ inputs.org-slug }}"
40
+ PIPELINE_SLUG="${{ inputs.pipeline-slug }}"
41
+ RETRY_STEP_KEY="${{ inputs.retry-step-key }}"
42
+ BUILDKITE_API_ACCESS_TOKEN="${{ secrets.buildkite-api-token }}"
43
+ COMMIT_SHA="${{ inputs.build-commit-sha }}"
44
+
45
+ # Performs a Buildkite request using a http method ($1) and an api path ($2)
46
+ perform_buildkite_request() {
47
+ local METHOD=$1
48
+ local BUILDKITE_API_PATH=$2
49
+
50
+ local BUILDKITE_API_URL="https://api.buildkite.com/v2/organizations/$ORG_SLUG/pipelines/$PIPELINE_SLUG/$BUILDKITE_API_PATH"
51
+
52
+ local RAW_RESPONSE
53
+
54
+ RAW_RESPONSE=$(
55
+ curl \
56
+ --fail-with-body \
57
+ --silent \
58
+ --show-error \
59
+ -X "$METHOD" \
60
+ -H "Authorization: Bearer $BUILDKITE_API_ACCESS_TOKEN" \
61
+ "$BUILDKITE_API_URL"
62
+ )
63
+
64
+ echo "$RAW_RESPONSE" | jq
65
+ }
66
+
67
+ # Gets the build(s) associated with the commit
68
+ get_buildkite_build() {
69
+ perform_buildkite_request "GET" "builds?commit=$COMMIT_SHA"
70
+ }
71
+
72
+ # Given a build id ($1) and a job id ($2), retry the given job
73
+ retry_buildkite_job() {
74
+ local BUILD_ID=$1
75
+ local JOB_ID=$2
76
+
77
+ perform_buildkite_request "PUT" "builds/$BUILD_ID/jobs/$JOB_ID/retry"
78
+ }
79
+
80
+ # Validates a Buildkite response ($1)
81
+ check_buildkite_error() {
82
+ local RESPONSE=$1
83
+
84
+ # Check if the response is empty
85
+ if [ -z "$RESPONSE" ] || [ "$(echo "$RESPONSE" | jq 'length')" -eq 0 ]; then
86
+ echo "❌ Buildkite API call returned an empty response."
87
+ exit 1
88
+ fi
89
+
90
+ # Check if the response contains an error message
91
+ RESPONSE_ERROR=$(echo "$RESPONSE" | jq .message 2>/dev/null || true)
92
+ if [[ -n "$RESPONSE_ERROR" && "$RESPONSE_ERROR" != 'null' ]]; then
93
+ echo "❌ Buildkite API call failed: $RESPONSE_ERROR"
94
+ exit 1
95
+ fi
96
+ }
97
+
98
+ BUILDKITE_GET_BUILD_RESPONSE=$(get_buildkite_build)
99
+ check_buildkite_error "$BUILDKITE_GET_BUILD_RESPONSE"
100
+
101
+ LATEST_BUILD=$(echo "$BUILDKITE_GET_BUILD_RESPONSE" | jq -r '.[0]')
102
+ LATEST_BUILD_NUMBER=$(echo "$LATEST_BUILD" | jq -r '.number')
103
+
104
+ SELECTED_JOB=$(echo "$LATEST_BUILD" | jq -r --arg step_key "$RETRY_STEP_KEY" '.jobs[] | select(.step_key == $step_key)')
105
+ SELECTED_JOB_ID=$(echo "$SELECTED_JOB" | jq -r '.id')
106
+ SELECTED_JOB_STATE=$(echo "$SELECTED_JOB" | jq -r '.state')
107
+
108
+ echo "ℹī¸ Build Number: $LATEST_BUILD_NUMBER"
109
+ echo "ℹī¸ Job ID for step '$RETRY_STEP_KEY': $SELECTED_JOB_ID"
110
+ echo "ℹī¸ Current job state for step '$RETRY_STEP_KEY': $SELECTED_JOB_STATE"
111
+
112
+ # all states: running, scheduled, passed, failing, failed, blocked, canceled, canceling, skipped, not_run, finished
113
+ ALLOWED_JOB_STATES=("passed" "failed" "canceled" "finished")
114
+ if [[ " ${ALLOWED_JOB_STATES[*]} " =~ [[:space:]]${SELECTED_JOB_STATE}[[:space:]] ]]; then
115
+ BUILDKITE_RETRY_JOB_RESPONSE=$(retry_buildkite_job "$LATEST_BUILD_NUMBER" "$SELECTED_JOB_ID")
116
+ check_buildkite_error "$BUILDKITE_RETRY_JOB_RESPONSE"
117
+
118
+ JOB_WEB_URL=$(echo "$BUILDKITE_RETRY_JOB_RESPONSE" | jq -r '.web_url')
119
+ echo "✅ Job succesfully retried: $JOB_WEB_URL"
120
+ elif [[ "$SELECTED_JOB_STATE" == "running" || "$SELECTED_JOB_STATE" == "scheduled" ]]; then
121
+ echo "⚠ī¸ Job is already in state '$SELECTED_JOB_STATE', no need to retry."
122
+ else
123
+ echo "❌ Cannot retry job in state '$SELECTED_JOB_STATE'"
124
+ fi
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ---
4
4
 
5
+ ## 1.1.1
6
+
7
+ ### Internal Changes
8
+
9
+ - Update `danger-rubocop` so that we can run it without `bundle exec`.
10
+
11
+ ## 1.1.0
12
+
13
+ ### New Features
14
+
15
+ - Reusable GitHub Workflow for retrying Buildkite jobs (#64)
16
+
5
17
  ## 1.0.2
6
18
 
7
19
  ### Bug Fixes
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-dangermattic (1.0.2)
4
+ danger-dangermattic (1.1.1)
5
5
  danger (~> 9.4)
6
6
  danger-plugin-api (~> 1.0)
7
- danger-rubocop (~> 0.12)
8
- rubocop (~> 1.61)
7
+ danger-rubocop (~> 0.13)
8
+ rubocop (~> 1.63)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
@@ -38,7 +38,7 @@ GEM
38
38
  terminal-table (>= 1, < 4)
39
39
  danger-plugin-api (1.0.0)
40
40
  danger (> 2.0)
41
- danger-rubocop (0.12.0)
41
+ danger-rubocop (0.13.0)
42
42
  danger
43
43
  rubocop (~> 1.0)
44
44
  diff-lcs (1.5.1)
@@ -67,7 +67,7 @@ GEM
67
67
  guard (~> 2.1)
68
68
  guard-compat (~> 1.1)
69
69
  rspec (>= 2.99.0, < 4.0)
70
- json (2.7.1)
70
+ json (2.7.2)
71
71
  kramdown (2.4.0)
72
72
  rexml
73
73
  kramdown-parser-gfm (1.1.0)
@@ -77,7 +77,7 @@ GEM
77
77
  rb-fsevent (~> 0.10, >= 0.10.3)
78
78
  rb-inotify (~> 0.9, >= 0.9.10)
79
79
  lumberjack (1.2.10)
80
- method_source (1.0.0)
80
+ method_source (1.1.0)
81
81
  nap (1.1.0)
82
82
  nenv (0.3.0)
83
83
  net-http (0.4.1)
@@ -92,22 +92,23 @@ GEM
92
92
  sawyer (~> 0.9)
93
93
  open4 (1.3.4)
94
94
  parallel (1.24.0)
95
- parser (3.3.0.5)
95
+ parser (3.3.1.0)
96
96
  ast (~> 2.4.1)
97
97
  racc
98
98
  pry (0.14.2)
99
99
  coderay (~> 1.1)
100
100
  method_source (~> 1.0)
101
- public_suffix (5.0.4)
102
- racc (1.7.3)
101
+ public_suffix (5.0.5)
102
+ racc (1.8.0)
103
103
  rainbow (3.1.1)
104
- rake (13.1.0)
104
+ rake (13.2.1)
105
105
  rb-fsevent (0.11.2)
106
- rb-inotify (0.10.1)
106
+ rb-inotify (0.11.1)
107
107
  ffi (~> 1.0)
108
108
  rchardet (1.8.0)
109
- regexp_parser (2.9.0)
110
- rexml (3.2.6)
109
+ regexp_parser (2.9.2)
110
+ rexml (3.2.8)
111
+ strscan (>= 3.0.9)
111
112
  rspec (3.13.0)
112
113
  rspec-core (~> 3.13.0)
113
114
  rspec-expectations (~> 3.13.0)
@@ -117,11 +118,11 @@ GEM
117
118
  rspec-expectations (3.13.0)
118
119
  diff-lcs (>= 1.2.0, < 2.0)
119
120
  rspec-support (~> 3.13.0)
120
- rspec-mocks (3.13.0)
121
+ rspec-mocks (3.13.1)
121
122
  diff-lcs (>= 1.2.0, < 2.0)
122
123
  rspec-support (~> 3.13.0)
123
124
  rspec-support (3.13.1)
124
- rubocop (1.61.0)
125
+ rubocop (1.63.5)
125
126
  json (~> 2.3)
126
127
  language_server-protocol (>= 3.17.0)
127
128
  parallel (~> 1.10)
@@ -129,26 +130,30 @@ GEM
129
130
  rainbow (>= 2.2.2, < 4.0)
130
131
  regexp_parser (>= 1.8, < 3.0)
131
132
  rexml (>= 3.2.5, < 4.0)
132
- rubocop-ast (>= 1.30.0, < 2.0)
133
+ rubocop-ast (>= 1.31.1, < 2.0)
133
134
  ruby-progressbar (~> 1.7)
134
135
  unicode-display_width (>= 2.4.0, < 3.0)
135
- rubocop-ast (1.31.1)
136
- parser (>= 3.3.0.4)
136
+ rubocop-ast (1.31.3)
137
+ parser (>= 3.3.1.0)
137
138
  rubocop-capybara (2.20.0)
138
139
  rubocop (~> 1.41)
139
140
  rubocop-factory_bot (2.25.1)
140
141
  rubocop (~> 1.41)
141
142
  rubocop-rake (0.6.0)
142
143
  rubocop (~> 1.0)
143
- rubocop-rspec (2.27.1)
144
+ rubocop-rspec (2.29.2)
144
145
  rubocop (~> 1.40)
145
146
  rubocop-capybara (~> 2.17)
146
147
  rubocop-factory_bot (~> 2.22)
148
+ rubocop-rspec_rails (~> 2.28)
149
+ rubocop-rspec_rails (2.28.3)
150
+ rubocop (~> 1.40)
147
151
  ruby-progressbar (1.13.0)
148
152
  sawyer (0.9.2)
149
153
  addressable (>= 2.3.5)
150
154
  faraday (>= 0.17.3, < 3)
151
155
  shellany (0.0.1)
156
+ strscan (3.1.0)
152
157
  terminal-table (3.0.2)
153
158
  unicode-display_width (>= 1.1.1, < 3)
154
159
  thor (1.3.1)
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
26
26
 
27
27
  # Danger plugins
28
- spec.add_dependency 'danger-rubocop', '~> 0.12'
28
+ spec.add_dependency 'danger-rubocop', '~> 0.13'
29
29
 
30
30
  # General ruby development
31
31
  spec.add_development_dependency 'bundler', '~> 2.0'
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'rspec', '~> 3.4'
36
36
 
37
37
  # Linting code and docs
38
- spec.add_dependency 'rubocop', '~> 1.61'
38
+ spec.add_dependency 'rubocop', '~> 1.63'
39
39
  spec.add_development_dependency 'rubocop-rake'
40
40
  spec.add_development_dependency 'rubocop-rspec'
41
41
  spec.add_development_dependency 'yard'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dangermattic
4
- VERSION = '1.0.2'
4
+ VERSION = '1.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-dangermattic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Automattic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-11 00:00:00.000000000 Z
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.12'
47
+ version: '0.13'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.12'
54
+ version: '0.13'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.61'
103
+ version: '1.63'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.61'
110
+ version: '1.63'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop-rake
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +202,7 @@ files:
202
202
  - ".buildkite/pipeline.yml"
203
203
  - ".bundle/config"
204
204
  - ".github/workflows/reusable-check-labels-on-issues.yml"
205
+ - ".github/workflows/reusable-retry-buildkite-step-on-events.yml"
205
206
  - ".github/workflows/reusable-run-danger.yml"
206
207
  - ".gitignore"
207
208
  - ".rubocop.yml"