Skip to content

Commit c6ea797

Browse files
authored
Merge pull request #88 from puppetlabs/forked-modules
workflow fixes and improvements
2 parents 2a8f96d + 07cdabd commit c6ea797

12 files changed

+338
-41
lines changed

.github/workflows/gem_ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ jobs:
7373
if: |
7474
contains(inputs.rake_task, 'coverage') &&
7575
inputs.runs_on == 'ubuntu-latest' &&
76-
inputs.ruby_version == '3.2'
76+
inputs.ruby_version == '3.2' &&
77+
secrets.CODECOV_TOKEN
7778
uses: codecov/codecov-action@v4
7879
with:
7980
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/labeller.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
name: Labeller
22

33
on:
4-
issues:
5-
types:
6-
- opened
7-
- labeled
8-
- unlabeled
9-
pull_request_target:
10-
types:
11-
- opened
12-
- labeled
13-
- unlabeled
4+
workflow_call:
5+
inputs:
6+
token:
7+
default: ''
8+
type: string
149

1510
jobs:
1611
label:
12+
name: ${{ github.event.action }} ${{ github.event_name }}
13+
# case if the workflow is called improperly
14+
if: |
15+
contains(fromJson('["puppetlabs", "puppet-toy-chest"]'), github.repository_owner) &&
16+
contains(fromJson('["pull_request_target", "issues"]'), github.event_name) &&
17+
contains(fromJson('["opened", "reopened", "labeled", "unlabeled"]'), github.event.action)
1718
runs-on: ubuntu-latest
1819
steps:
19-
2020
- uses: puppetlabs/[email protected]
2121
name: Label issues or pull requests
2222
with:
2323
label_name: community
2424
label_color: '5319e7'
2525
org_membership: puppetlabs
2626
fail_if_member: 'true'
27-
token: ${{ secrets.IAC_COMMUNITY_LABELER }}
27+
token: ${{ inputs.token != '' && inputs.token || secrets.IAC_COMMUNITY_TOKEN }}

.github/workflows/mend_ruby.yml

+39-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,42 @@ name: mend
44

55
on:
66
workflow_call:
7+
inputs:
8+
api_key:
9+
default: ''
10+
type: string
11+
token:
12+
default: ''
13+
type: string
14+
product_name:
15+
default: 'content-and-tooling'
16+
type: string
717

8-
jobs:
18+
env:
19+
MEND_API_KEY: ${{ secrets.MEND_API_KEY != '' && secrets.MEND_API_KEY || inputs.api_key }}
20+
MEND_TOKEN: ${{ secrets.MEND_TOKEN != '' && secrets.MEND_TOKEN || inputs.token }}
21+
PRODUCT_NAME: ${{ inputs.PRODUCT_NAME != '' && inputs.PRODUCT_NAME || inputs.product_name }}
22+
REQUIRE_SECRETS: MEND_API_KEY MEND_TOKEN
923

24+
jobs:
1025
mend:
1126
runs-on: "ubuntu-latest"
27+
continue-on-error: ${{ contains(fromJson('["puppetlabs","puppet-toy-chest"]'), github.repository_owner) != true }}
1228
steps:
29+
- name: "check requirements"
30+
run: |
31+
declare -a MISSING
32+
for V in ${REQUIRE_SECRETS} ; do
33+
[[ -z "${!V}" ]] && MISSING+=($V)
34+
done
35+
if [ ${#MISSING[@]} -gt 0 ] ; then
36+
echo "::warning::missing required secrets: ${MISSING[@]}"
37+
exit 1
38+
fi
39+
1340
# If we are on a PR, checkout the PR head sha, else checkout the default branch
1441
- name: "Set the checkout ref"
42+
if: success()
1543
id: set_ref
1644
run: |
1745
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
@@ -21,32 +49,38 @@ jobs:
2149
fi
2250
2351
- name: "checkout"
52+
if: success()
2453
uses: "actions/checkout@v4"
2554
with:
2655
fetch-depth: 1
2756
ref: ${{ steps.set_ref.outputs.ref }}
2857

2958
- name: "setup ruby"
59+
if: success()
3060
uses: "ruby/setup-ruby@v1"
3161
with:
3262
ruby-version: 2.7
3363

3464
- name: "bundle lock"
65+
if: success()
3566
run: bundle lock
3667

3768
- uses: "actions/setup-java@v4"
69+
if: success()
3870
with:
3971
distribution: "temurin"
4072
java-version: "17"
4173

4274
- name: "download"
75+
if: success()
4376
run: curl -o wss-unified-agent.jar https://unified-agent.s3.amazonaws.com/wss-unified-agent.jar
4477

4578
- name: "scan"
79+
if: success()
4680
run: java -jar wss-unified-agent.jar
4781
env:
48-
WS_APIKEY: ${{ secrets.MEND_API_KEY }}
82+
WS_APIKEY: ${{ env.MEND_API_KEY }}
4983
WS_WSS_URL: https://saas-eu.whitesourcesoftware.com/agent
50-
WS_USERKEY: ${{ secrets.MEND_TOKEN }}
51-
WS_PRODUCTNAME: "content-and-tooling"
52-
WS_PROJECTNAME: ${{ github.event.repository.name }}
84+
WS_USERKEY: ${{ env.MEND_TOKEN }}
85+
WS_PRODUCTNAME: ${{ env.PRODUCT_NAME }}
86+
WS_PROJECTNAME: ${{ github.event.repository.name }}

.github/workflows/module_acceptance.yml

+19-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ on:
1414
required: false
1515
default: ''
1616
type: "string"
17-
17+
kernel_modules:
18+
description: "Volume map host kernel /lib/modules into docker container"
19+
default: true
20+
type: boolean
21+
disable_apparmor:
22+
description: "Disable and stop apparmor"
23+
default: false
24+
type: boolean
1825

1926
jobs:
2027

@@ -68,6 +75,16 @@ jobs:
6875
- name: "Checkout"
6976
uses: "actions/checkout@v4"
7077

78+
- name: "Disable Apparmor"
79+
if: ${{ inputs.disable_apparmor }}
80+
run: |
81+
if command -v apparmor_parser >/dev/null ; then
82+
sudo find /etc/apparmor.d/ -maxdepth 1 -type f -exec ln -sf {} /etc/apparmor.d/disable/ \;
83+
sudo apparmor_parser -R /etc/apparmor.d/disable/* || true
84+
sudo systemctl disable apparmor
85+
sudo systemctl stop apparmor
86+
fi
87+
7188
- name: "Setup ruby"
7289
uses: "ruby/setup-ruby@v1"
7390
with:
@@ -82,7 +99,7 @@ jobs:
8299
83100
- name: "Provision environment"
84101
run: |
85-
if [[ "${{matrix.platforms.provider}}" == "docker" ]]; then
102+
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then
86103
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}"
87104
else
88105
DOCKER_RUN_OPTS=''

.github/workflows/module_release.yml

+108-16
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,139 @@ name: "Module Release"
55

66
on:
77
workflow_call:
8+
inputs:
9+
tag:
10+
description: "Enter an old tag, or blank to tag HEAD of branch"
11+
default: ''
12+
type: string
13+
release:
14+
description: "Create a release on Github"
15+
type: boolean
16+
default: true
17+
publish:
18+
description: "Publish to forge.puppet.com"
19+
type: boolean
20+
default: true
21+
edit:
22+
description: "Re-tag and regenerate release notes"
23+
type: boolean
24+
default: false
25+
26+
env:
27+
FORGE_API_KEY: ${{ secrets.FORGE_API_KEY }}
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
830

931
jobs:
32+
check:
33+
runs-on: "ubuntu-latest"
34+
steps:
35+
- name: "Check Requirements"
36+
if: ${{ inputs.publish == true || inputs.publish == 'true' }}
37+
run: |
38+
if [[ -z "${FORGE_API_KEY}" ]] ; then
39+
echo "::error::missing required secret: FORGE_API_KEY"
40+
exit 1
41+
fi
42+
1043
release:
11-
name: "Release"
44+
name: ${{ inputs.tag != '' && inputs.tag || 'new' }}
45+
needs: check
1246
runs-on: "ubuntu-latest"
13-
if: github.repository_owner == 'puppetlabs'
1447

1548
steps:
16-
1749
- name: "Checkout"
1850
uses: "actions/checkout@v4"
1951
with:
2052
ref: "${{ github.ref }}"
2153
clean: true
2254
fetch-depth: 0
55+
fetch-tags: true
56+
57+
- name: "Checkout tag ${{ inputs.tag }}"
58+
if: ${{ inputs.tag != '' }}
59+
run: |
60+
git checkout refs/tags/${{ inputs.tag }}
2361
24-
- name: "Get version"
25-
id: "get_version"
62+
- name: "Get metadata"
63+
id: metadata
2664
run: |
27-
echo "version=$(jq --raw-output .version metadata.json)" >> $GITHUB_OUTPUT
65+
metadata_version=$(jq --raw-output .version metadata.json)
66+
if [[ -n "${{ inputs.tag }}" ]] ; then
67+
tag=${{ inputs.tag }}
68+
if [[ "${metadata_version}" != "${tag/v}" ]] ; then
69+
echo "::error::tag ${tag/v} does not match metadata version ${metadata_version}"
70+
exit 1
71+
fi
72+
else
73+
tag="v${metadata_version}"
74+
fi
75+
echo "tag=${tag}" >> $GITHUB_OUTPUT
76+
echo "version=${metadata_version}" >> $GITHUB_OUTPUT
2877
29-
- name: "PDK build"
78+
- name: "PDK build ${{ steps.metadata.outputs.version }}"
3079
uses: "docker://puppet/pdk:3.0.0.0"
3180
with:
3281
args: "build"
3382

34-
- name: "Generate release notes"
83+
- name: "Generate release notes for Github"
84+
continue-on-error: true
3585
run: |
3686
export GH_HOST=github.com
3787
gh extension install chelnak/gh-changelog
38-
gh changelog get --latest > OUTPUT.md
39-
env:
40-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
# TODO replace sed when gh-changelog supports templates
89+
gh changelog get --latest | \
90+
sed -e "1,/^\[Full Changelog\]/ d" \
91+
-e 's/(\[\([^]]*\)\]([^)]*))$/@\1/g' \
92+
-e 's/\[#\([0-9]*\)\]([^)]*)/#\1/g' > OUTPUT.md
93+
echo "::group::release notes"
94+
cat OUTPUT.md
95+
echo "::endgroup::"
96+
97+
- name: "Tag ${{ steps.metadata.outputs.tag }}"
98+
id: tag
99+
run: |
100+
# create an annotated tag -- gh release create DOES NOT do this for us!
101+
# TODO move this to an automatic action when a release_prep PR is merged
102+
git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com"
103+
git config --local user.name "GitHub Actions"
104+
105+
# overwrite existing tag?
106+
if [[ -n "${{ inputs.tag }}" ]] ; then
107+
if [[ "${{ inputs.edit }}" == "true" ]] ; then
108+
arg="-f"
109+
else
110+
skip_tag=1
111+
fi
112+
fi
113+
114+
if [[ -z "${skip_tag}" ]] ; then
115+
GIT_COMMITTER_DATE="$(git log --format=%aD ...HEAD^)" git tag -a $arg -F OUTPUT.md "${{ steps.metadata.outputs.tag }}"
116+
git push $arg origin tag "${{ steps.metadata.outputs.tag }}"
117+
fi
118+
119+
if gh release view "${{ steps.metadata.outputs.tag }}" > /dev/null ; then
120+
echo "release_action=edit" >> $GITHUB_OUTPUT
121+
echo "undraft=${{ inputs.edit }}" >> $GITHUB_OUTPUT
122+
else
123+
echo "release_action=create" >> $GITHUB_OUTPUT
124+
fi
125+
126+
# is latest tag?
127+
LAST_TAG=$(git for-each-ref refs/tags --sort='-*creatordate' --format='%(refname:short)' --count=1)
128+
if [[ "${LAST_TAG}" == "${{ steps.metadata.outputs.tag }}" ]] ; then
129+
echo "latest=true" >> $GITHUB_OUTPUT
130+
else
131+
echo "latest=false" >> $GITHUB_OUTPUT
132+
fi
41133
42-
- name: "Create release"
134+
- name: "${{ steps.tag.outputs.release_action }} release for ${{ steps.metadata.outputs.tag }}"
135+
if: ${{ inputs.release == true || inputs.release == 'true' || steps.tag.outputs.undraft == 'true' }}
43136
run: |
44-
gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md
45-
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
137+
gh release ${{ steps.tag.outputs.release_action }} ${{ steps.metadata.outputs.tag }} --latest=${{ steps.tag.outputs.latest }} --draft=false --title ${{ steps.metadata.outputs.tag }} -F OUTPUT.md
47138
48139
- name: "Publish module"
140+
if: ${{ inputs.publish == true || inputs.publish == 'true' }}
49141
uses: "docker://puppet/pdk:3.0.0.0"
50142
with:
51-
args: 'release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force'
143+
args: 'release publish --forge-token ${{ env.FORGE_API_KEY }} --force'

0 commit comments

Comments
 (0)