simp-beaker-helpers 1.32.1 → 1.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/pr_acceptance.yml +4 -4
- data/.github/workflows/pr_tests.yml +1 -1
- data/.github/workflows/tag_deploy_rubygem.yml +2 -2
- data/.rspec +0 -1
- data/.rubocop.yml +166 -165
- data/CHANGELOG.md +4 -0
- data/Gemfile +16 -20
- data/README.md +7 -0
- data/lib/simp/beaker_helpers/version.rb +3 -1
- data/lib/simp/beaker_helpers.rb +9 -4
- data/simp-beaker-helpers.gemspec +17 -16
- metadata +44 -39
- data/.github/workflows/pr_glci.yml +0 -190
- data/.github/workflows/pr_glci_cleanup.yml +0 -105
- data/.github/workflows/pr_glci_manual.yml +0 -143
@@ -1,105 +0,0 @@
|
|
1
|
-
# When a PR is closed, clean up any associated GitLab CI pipelines & branch
|
2
|
-
#
|
3
|
-
# * Cancels all GLCI pipelines associated with the PR HEAD ref (branch)
|
4
|
-
# * Removes the PR HEAD branch from the corresponding gitlab.com/org/ project
|
5
|
-
#
|
6
|
-
# ------------------------------------------------------------------------------
|
7
|
-
#
|
8
|
-
# NOTICE: **This file is maintained with puppetsync**
|
9
|
-
#
|
10
|
-
# This file is updated automatically as part of a standardized asset baseline.
|
11
|
-
#
|
12
|
-
# The next baseline sync will overwrite any local changes to this file!
|
13
|
-
#
|
14
|
-
# ==============================================================================
|
15
|
-
#
|
16
|
-
# GitHub Action Secrets variables available for this pipeline:
|
17
|
-
#
|
18
|
-
# GitHub Secret variable Type Notes
|
19
|
-
# ------------------------ -------- ----------------------------------------
|
20
|
-
# GITLAB_API_PRIVATE_TOKEN Secure Should have `api` scope
|
21
|
-
# GITLAB_API_URL Optional
|
22
|
-
#
|
23
|
-
# The secure vars will be filtered in GitHub Actions log output, and aren't
|
24
|
-
# provided to untrusted builds (i.e, triggered by PR from another repository)
|
25
|
-
#
|
26
|
-
# ------------------------------------------------------------------------------
|
27
|
-
#
|
28
|
-
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
|
29
|
-
#
|
30
|
-
---
|
31
|
-
name: PR GLCI Cleanup
|
32
|
-
on:
|
33
|
-
pull_request_target:
|
34
|
-
types: [closed]
|
35
|
-
|
36
|
-
jobs:
|
37
|
-
cleanup-glci-branch:
|
38
|
-
name: 'Clean up GLCI'
|
39
|
-
# This conditional provides an extra safety control, in case the workflow's
|
40
|
-
# `on` section is inadventently modified without considering the security
|
41
|
-
# implications.
|
42
|
-
if: github.event_name == 'pull_request_target' && github.event.action == 'closed'
|
43
|
-
runs-on: ubuntu-latest
|
44
|
-
steps:
|
45
|
-
- uses: actions/checkout@v3
|
46
|
-
with:
|
47
|
-
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
48
|
-
ref: ${{ github.event.pull_request.head.ref }}
|
49
|
-
- name: Trigger CI when user has Repo Permissions
|
50
|
-
env:
|
51
|
-
GITLAB_SERVER_URL: ${{ secrets.GITLAB_SERVER_URL }} # https://gitlab.com
|
52
|
-
GITLAB_API_URL: ${{ secrets.GITLAB_API_URL }} # https://gitlab.com/api/v4
|
53
|
-
GITLAB_ORG: ${{ github.event.organization.login }}
|
54
|
-
GITLAB_API_PRIVATE_TOKEN: ${{ secrets.GITLAB_API_PRIVATE_TOKEN }}
|
55
|
-
GIT_BRANCH: ${{ github.event.pull_request.head.ref }}
|
56
|
-
run: |
|
57
|
-
GITLAB_SERVER_URL="${GITLAB_SERVER_URL:-https://gitlab.com}"
|
58
|
-
GITLAB_API_URL="${GITLAB_API_URL:-${GITLAB_SERVER_URL}/api/v4}"
|
59
|
-
GIT_BRANCH="${GIT_BRANCH:-GITHUB_HEAD_REF}"
|
60
|
-
GITXXB_REPO_NAME="${GITHUB_REPOSITORY/$GITHUB_REPOSITORY_OWNER\//}"
|
61
|
-
GITLAB_PROJECT_ID="${GITLAB_ORG}%2F${GITXXB_REPO_NAME}"
|
62
|
-
# --http1.0 avoids an HTTP/2 load balancing issue when run from GA
|
63
|
-
CURL_CMD=(curl --http1.0 --fail --silent --show-error \
|
64
|
-
--header "Authorization: Bearer $GITLAB_API_PRIVATE_TOKEN" \
|
65
|
-
--header "Content-Type: application/json" \
|
66
|
-
--header "Accept: application/json" \
|
67
|
-
)
|
68
|
-
|
69
|
-
# Cancel any active/pending GitLab CI pipelines for the same project+branch
|
70
|
-
active_pipeline_ids=()
|
71
|
-
for pipe_status in created waiting_for_resource preparing pending running; do
|
72
|
-
echo " ---- checking for CI pipelines with status '$pipe_status' for project '$GITLAB_PROJECT_ID', branch '$GIT_BRANCH'"
|
73
|
-
url="${GITLAB_API_URL}/projects/${GITLAB_PROJECT_ID}/pipelines?ref=${GIT_BRANCH}&status=${pipe_status}"
|
74
|
-
active_pipelines="$("${CURL_CMD[@]}" "$url" | jq -r '.[] | .id , .web_url')"
|
75
|
-
active_pipeline_ids+=($(echo "$active_pipelines" | grep -E '^[0-9]*$'))
|
76
|
-
printf "$active_pipelines\n\n"
|
77
|
-
done
|
78
|
-
if [ "${#active_pipeline_ids[@]}" -gt 0 ]; then
|
79
|
-
printf "\nFound %s active pipeline ids:\n" "${#active_pipeline_ids[@]}"
|
80
|
-
echo "${active_pipeline_ids[@]}"
|
81
|
-
for pipe_id in "${active_pipeline_ids[@]}"; do
|
82
|
-
printf "\n ------ Cancelling pipeline ID %s...\n" "$pipe_id"
|
83
|
-
"${CURL_CMD[@]}" --request POST "${GITLAB_API_URL}/projects/${GITLAB_PROJECT_ID}/pipelines/${pipe_id}/cancel"
|
84
|
-
done
|
85
|
-
else
|
86
|
-
echo No active pipelines found
|
87
|
-
fi
|
88
|
-
|
89
|
-
echo "== Removing $GIT_BRANCH from gitlab"
|
90
|
-
git remote add gitlab "https://oauth2:${GITLAB_API_PRIVATE_TOKEN}@${GITLAB_SERVER_URL#*://}/${GITLAB_ORG}/${GITXXB_REPO_NAME}.git"
|
91
|
-
git push gitlab ":${GIT_BRANCH}" -f || : # attempt to un-weird GLCI's `changed` tracking
|
92
|
-
|
93
|
-
### examine_contexts:
|
94
|
-
### name: 'Examine Context contents'
|
95
|
-
### if: always()
|
96
|
-
### runs-on: ubuntu-latest
|
97
|
-
### steps:
|
98
|
-
### - name: Dump contexts
|
99
|
-
### env:
|
100
|
-
### GITHUB_CONTEXT: ${{ toJson(github) }}
|
101
|
-
### run: echo "$GITHUB_CONTEXT"
|
102
|
-
### run: echo "$ENV_CONTEXT"
|
103
|
-
### - name: Dump env vars
|
104
|
-
### run: env | sort
|
105
|
-
|
@@ -1,143 +0,0 @@
|
|
1
|
-
# Manually trigger GLCI pipelines for a PR
|
2
|
-
# ------------------------------------------------------------------------------
|
3
|
-
#
|
4
|
-
# NOTICE: **This file is maintained with puppetsync**
|
5
|
-
|
6
|
-
# This file is updated automatically as part of a standardized asset baseline.
|
7
|
-
#
|
8
|
-
# The next baseline sync will overwrite any local changes to this file!
|
9
|
-
#
|
10
|
-
# ==============================================================================
|
11
|
-
#
|
12
|
-
# This pipeline uses the following GitHub Action Secrets:
|
13
|
-
#
|
14
|
-
# GitHub Secret variable Type Notes
|
15
|
-
# ------------------------ -------- ----------------------------------------
|
16
|
-
# GITLAB_API_PRIVATE_TOKEN Required GitLab token (should have `api` scope)
|
17
|
-
# NO_SCOPE_GITHUB_TOKEN Required GitHub token (should have no scopes)
|
18
|
-
# GITLAB_SERVER_URL Optional Specify a GL server other than gitlab.com
|
19
|
-
# The secure vars will be filtered in GitHub Actions log output, and aren't
|
20
|
-
# provided to untrusted builds (i.e, triggered by PR from another repository)
|
21
|
-
#
|
22
|
-
# ------------------------------------------------------------------------------
|
23
|
-
#
|
24
|
-
# NOTES:
|
25
|
-
# It is necessary to provide NO_SCOPE_GITHUB_TOKEN because $secrets.GITHUB_AUTO
|
26
|
-
# is NOT provide to manually-triggered (`workflow_dispatch`) events, in order
|
27
|
-
# to prevent recursive triggers between workflows
|
28
|
-
#
|
29
|
-
# Reference:
|
30
|
-
#
|
31
|
-
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token
|
32
|
-
---
|
33
|
-
name: 'Manual: PR GLCI'
|
34
|
-
|
35
|
-
on:
|
36
|
-
workflow_dispatch:
|
37
|
-
inputs:
|
38
|
-
pr_number:
|
39
|
-
description: "PR number to trigger GLCI"
|
40
|
-
required: true
|
41
|
-
|
42
|
-
jobs:
|
43
|
-
glci-syntax:
|
44
|
-
name: '.gitlab-ci.yml Syntax'
|
45
|
-
runs-on: ubuntu-latest
|
46
|
-
outputs:
|
47
|
-
valid: ${{ steps.validate-glci-file.outputs.valid }}
|
48
|
-
pr_head_ref: ${{ steps.get-pr.outputs.pr_head_ref }}
|
49
|
-
pr_head_sha: ${{ steps.get-pr.outputs.pr_head_sha }}
|
50
|
-
pr_head_label: ${{ steps.get-pr.outputs.pr_head_label }}
|
51
|
-
pr_head_full_name: ${{ steps.get-pr.outputs.pr_full_name }}
|
52
|
-
steps:
|
53
|
-
- uses: actions/github-script@v6
|
54
|
-
id: get-pr
|
55
|
-
with:
|
56
|
-
github-token: ${{secrets.NO_SCOPE_GITHUB_TOKEN}}
|
57
|
-
# See:
|
58
|
-
# - https://octokit.github.io/rest.js/
|
59
|
-
script: |
|
60
|
-
console.log(`== pr number: ${context.payload.inputs.pr_number}`)
|
61
|
-
const pr = await github.request('get /repos/{owner}/{repo}/pulls/{pull_number}', {
|
62
|
-
headers: {
|
63
|
-
accept: 'application/vnd.github.v3+json'
|
64
|
-
},
|
65
|
-
owner: context.repo.owner,
|
66
|
-
repo: context.repo.repo,
|
67
|
-
pull_number: context.payload.inputs.pr_number
|
68
|
-
});
|
69
|
-
|
70
|
-
console.log("\n\n== pr\n");
|
71
|
-
console.log(pr);
|
72
|
-
console.log("\n\n== pr.data.head\n");
|
73
|
-
console.log(pr.data.head);
|
74
|
-
console.log(pr.status);
|
75
|
-
|
76
|
-
// PR must have been returned
|
77
|
-
if ( pr.status != 200 ) {
|
78
|
-
//#console.log(`::error ::Error looking up PR \#${context.payload.inputs.pr_number}: HTTP Response ${pr.status}`)
|
79
|
-
return(false)
|
80
|
-
}
|
81
|
-
|
82
|
-
// TODO: should either of these conditions really prevent a GLCI trigger?
|
83
|
-
if ( pr.data.state != 'open' ) {
|
84
|
-
console.log(`::error ::PR# ${context.payload.inputs.pr_number} is not open`)
|
85
|
-
}
|
86
|
-
if ( pr.data.merged ) {
|
87
|
-
console.log(`::error ::PR# ${context.payload.inputs.pr_number} is already merged`)
|
88
|
-
}
|
89
|
-
core.setOutput( 'pr_head_sha', pr.data.head.sha )
|
90
|
-
core.setOutput( 'pr_head_ref', pr.data.head.ref )
|
91
|
-
core.setOutput( 'pr_head_label', pr.data.head.label )
|
92
|
-
core.setOutput( 'pr_head_full_name', pr.data.head.full_name )
|
93
|
-
- uses: actions/checkout@v3
|
94
|
-
with:
|
95
|
-
repository: ${{ steps.get-pr.outputs.pr_head_full_name }}
|
96
|
-
ref: ${{ steps.get-pr.outputs.pr_head_sha }}
|
97
|
-
token: ${{secrets.NO_SCOPE_GITHUB_TOKEN}}
|
98
|
-
clean: true
|
99
|
-
- name: 'Validate GLCI file syntax'
|
100
|
-
id: validate-glci-file
|
101
|
-
uses: simp/github-action-gitlab-ci-syntax-check@main
|
102
|
-
with:
|
103
|
-
gitlab_api_private_token: ${{ secrets.GITLAB_API_PRIVATE_TOKEN }}
|
104
|
-
gitlab_api_url: ${{ secrets.GITLAB_API_URL }} # https://gitlab.com/api/v4
|
105
|
-
|
106
|
-
trigger-when-user-has-repo-permissions:
|
107
|
-
name: 'Trigger CI'
|
108
|
-
needs: [ glci-syntax ]
|
109
|
-
runs-on: ubuntu-latest
|
110
|
-
steps:
|
111
|
-
- uses: actions/checkout@v3
|
112
|
-
with:
|
113
|
-
repository: ${{ needs.glci-syntax.outputs.pr_head_full_name }}
|
114
|
-
ref: ${{ needs.glci-syntax.outputs.pr_head_sha }}
|
115
|
-
token: ${{secrets.NO_SCOPE_GITHUB_TOKEN}}
|
116
|
-
fetch-depth: 0 # Need full checkout to push to gitlab mirror
|
117
|
-
clean: true
|
118
|
-
- name: Trigger CI when user has Repo Permissions
|
119
|
-
uses: simp/github-action-gitlab-ci-pipeline-trigger@v1
|
120
|
-
with:
|
121
|
-
git_hashref: ${{ needs.glci-syntax.outputs.pr_head_sha }}
|
122
|
-
git_branch: ${{ needs.glci-syntax.outputs.pr_head_ref }}
|
123
|
-
gitlab_api_private_token: ${{ secrets.GITLAB_API_PRIVATE_TOKEN }}
|
124
|
-
gitlab_group: ${{ github.event.organization.login }}
|
125
|
-
github_repository: ${{ github.repository }}
|
126
|
-
github_repository_owner: ${{ github.repository_owner }}
|
127
|
-
|
128
|
-
### examine_contexts:
|
129
|
-
### needs: [ glci-syntax ]
|
130
|
-
### name: 'Examine Context contents'
|
131
|
-
### if: always()
|
132
|
-
### runs-on: ubuntu-latest
|
133
|
-
### steps:
|
134
|
-
### - name: Dump contexts
|
135
|
-
### env:
|
136
|
-
### GITHUB_CONTEXT: ${{ toJson(github) }}
|
137
|
-
### run: echo "$GITHUB_CONTEXT"
|
138
|
-
### - name: Dump 'needs' context
|
139
|
-
### env:
|
140
|
-
### ENV_CONTEXT: ${{ toJson(needs) }}
|
141
|
-
### run: echo "$ENV_CONTEXT"
|
142
|
-
### - name: Dump env vars
|
143
|
-
### run: env | sort
|