Skip to content

Commit 5f87cbf

Browse files
authored
(SIMP-10633) Update standardized assets (#86)
1 parent b2dcdfb commit 5f87cbf

File tree

2 files changed

+105
-22
lines changed

2 files changed

+105
-22
lines changed

.github/workflows/release_rpms.yml

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# GitHub Secret variable Notes
1414
# ------------------------------- ---------------------------------------
1515
# SIMP_CORE_REF_FOR_BUILDING_RPMS simp-core ref (tag) to use to build
16-
# RPMs with `rake pkg:single`
16+
# RPMs with `rake pkg:single` against
17+
# `build/rpms/dependencies.yaml`
1718
# SIMP_DEV_GPG_SIGNING_KEY GPG signing key's secret key
1819
# SIMP_DEV_GPG_SIGNING_KEY_ID User ID (name) of signing key
1920
# SIMP_DEV_GPG_SIGNING_KEY_PASSPHRASE Passphrase to use GPG signing key
@@ -26,6 +27,7 @@
2627
# * If triggered by another workflow, it will be necessary to provide a GitHub
2728
# access token via the the `target_repo_token` parameter
2829
#
30+
#
2931
---
3032
name: 'RELENG: Build + attach RPMs to GitHub Release'
3133

@@ -61,39 +63,64 @@ on:
6163
target_repo_token:
6264
description: "API token for uploading to target repo"
6365
required: false
66+
path_to_build:
67+
# Example: simp-core builds pupmod from . and simp* from src/assets/simp
68+
description: "Subpath to alternative RPM project"
69+
required: false
6470
dry_run:
6571
description: "Dry run (Test-build RPMs)"
6672
required: false
6773
default: 'no'
74+
verbose:
75+
description: 'Verbose RPM builds when "yes"'
76+
required: false
77+
default: 'no'
6878

6979
env:
7080
TARGET_REPO: ${{ (github.event.inputs.target_repo != null && format('{0}/{1}', github.repository_owner, github.event.inputs.target_repo)) || github.repository }}
7181
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
7282

7383
jobs:
7484
create-and-attach-rpms-to-github-release:
75-
name: Build and attach RPMs to Release
85+
name: >
86+
Build and attach RPMs to Release:
87+
${{ (github.event.inputs.target_repo != null && format('{0}/{1}', github.repository_owner, github.event.inputs.target_repo)) || github.repository }}
88+
${{ github.event.inputs.release_tag }}
89+
(build os: ${{ github.event.inputs.build_container_os }})
7690
runs-on: ubuntu-20.04
7791
steps:
7892
- name: "Validate inputs"
93+
id: validate-inputs
7994
run: |
8095
if ! [[ "$TARGET_REPO" =~ ^[a-z0-9][a-z0-9-]+/[a-z0-9][a-z0-9_-]+$ ]]; then
8196
printf '::error ::Target repository name has invalid format: %s\n' "$TARGET_REPO"
8297
exit 88
8398
fi
8499
85-
if ! [[ "$RELEASE_TAG" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta|pre)?([0-9]+)?)?$ ]]; then
86-
printf '::error ::Release Tag format is not SemVer or SemVer-ish RPM: %s\n' "$RELEASE_TAG"
100+
if [[ "$RELEASE_TAG" =~ ^(simp-|v)?([0-9]+\.[0-9]+\.[0-9]+)(-(rc|RC|[Aa]lpha|[Bb]eta|pre|post)?([0-9]+)?)?$ ]]; then
101+
if [ -n "${BASH_REMATCH[5]}" ]; then
102+
echo "::set-output name=prebuild_number::${BASH_REMATCH[5]#-}"
103+
fi
104+
if [ -n "${BASH_REMATCH[3]}" ]; then
105+
echo "::set-output name=prebuild_suffix::${BASH_REMATCH[3]#-}"
106+
fi
107+
if [ -n "${BASH_REMATCH[2]}" ]; then
108+
echo "::set-output name=build_semver::${BASH_REMATCH[2]}"
109+
fi
110+
else
111+
printf '::error ::Release Tag format is not SemVer, X.Y.Z-R, X.Y.Z-<prerelease>: "%s"\n' "$RELEASE_TAG"
87112
exit 88
88113
fi
89114
90115
- name: >
91116
Query info for ${{ env.TARGET_REPO }}
92-
release ${{ github.event.inputs.release_tag }}
117+
release ${{ github.event.inputs.release_tag }} ${{ steps.validate-inputs.outputs.prebuild_suffix }}
118+
build os ${{ github.event.inputs.build_container_os }}
93119
(autocreate_release = '${{ github.event.inputs.autocreate_release }}')
94120
id: release-api
95121
env:
96122
AUTOCREATE_RELEASE: ${{ github.event.inputs.autocreate_release }}
123+
PREBUILD_TAG: ${{ steps.validate-inputs.outputs.prebuild_suffix }}
97124
uses: actions/github-script@v4
98125
with:
99126
github-token: ${{ github.event.inputs.target_repo_token || secrets.GITHUB_TOKEN }}
@@ -103,7 +130,8 @@ jobs:
103130
const autocreate_release = (process.env.AUTOCREATE_RELEASE == 'yes')
104131
const owner_data = { owner: owner, repo: repo }
105132
const release_data = Object.assign( {tag: tag}, owner_data )
106-
const create_release_data = Object.assign( {tag_name: tag}, owner_data )
133+
const prerelease = process.env.PREBUILD_TAG ? true : false
134+
const create_release_data = Object.assign( {tag_name: tag, prerelease: prerelease}, owner_data )
107135
const tag_data = Object.assign( {ref: `tags/${tag}`}, owner_data )
108136
109137
function id_from_release(data) {
@@ -168,7 +196,35 @@ jobs:
168196
clean: true
169197
fetch-depth: 0
170198

171-
- name: 'Build & Sign RPMs for ${{ github.event.inputs.release_tag }} Release'
199+
- name: 'Customize RPM Release tag via build/rpm_metadata/release (pre-release only)'
200+
if: steps.validate-inputs.outputs.prebuild_suffix
201+
env:
202+
BUILD_SEMVER: ${{ steps.validate-inputs.outputs.build_semver }}
203+
PREBUILD_TAG: ${{ steps.validate-inputs.outputs.prebuild_suffix }}
204+
PREBUILD_NUMBER: ${{ steps.validate-inputs.outputs.prebuild_number }}
205+
# Note: To accomodate the capabilities of EL7's version of RPM, the
206+
# release number is formatted according to the Fedora Packaging
207+
# Guidelines' "Traditional versioning" conventions:
208+
#
209+
# - https://fedoraproject.org/en-US/packaging-guidelines/Versioning/
210+
# - https://fedoraproject.org/wiki/Package_Versioning_Examples
211+
#
212+
run: |
213+
mkdir -p build/rpm_metadata
214+
# Special case for simp-doc's unique data format in /release
215+
if [[ "$TARGET_REPO" =~ ^simp\/simp-doc$ ]]; then
216+
echo "version: $BUILD_SEMVER" > build/rpm_metadata/release
217+
echo "release: 0.${PREBUILD_NUMBER:-$GITHUB_RUN_NUMBER}.${PREBUILD_TAG}" >> build/rpm_metadata/release
218+
printf '::warning ::Added file build/rpm_metadata/release with content "%s"\n' "$(cat build/rpm_metadata/release)"
219+
else
220+
echo "0.${PREBUILD_NUMBER:-$GITHUB_RUN_NUMBER}.${PREBUILD_TAG}" > build/rpm_metadata/release
221+
printf '::warning ::Added file build/rpm_metadata/release with content "%s"\n' "$(cat build/rpm_metadata/release)"
222+
fi
223+
224+
- name: >
225+
Build & Sign RPMs for
226+
${{ github.event.inputs.release_tag }}
227+
Release (${{ github.event.inputs.build_container_os }})
172228
uses: simp/github-action-build-and-sign-pkg-single-rpm@v2
173229
id: build-and-sign-rpm
174230
with:
@@ -177,6 +233,8 @@ jobs:
177233
gpg_signing_key_passphrase: ${{ secrets.SIMP_DEV_GPG_SIGNING_KEY_PASSPHRASE }}
178234
simp_core_ref_for_building_rpms: ${{ secrets.SIMP_CORE_REF_FOR_BUILDING_RPMS }}
179235
simp_builder_docker_image: 'docker.io/simpproject/simp_build_${{ github.event.inputs.build_container_os }}:latest'
236+
path_to_build: "${{ (github.event.inputs.path_to_build != null && format('{0}/{1}', github.workspace, github.event.inputs.path_to_build)) || github.workspace }}"
237+
verbose: ${{ github.event.inputs.verbose }}
180238
181239
- name: "Wipe all previous assets from GitHub Release (when clean == 'yes')"
182240
if: ${{ github.event.inputs.clean == 'yes' && github.event.inputs.dry_run != 'yes' }}
@@ -197,7 +255,7 @@ jobs:
197255
await github.repos.deleteReleaseAsset({ owner, repo, asset_id })
198256
})
199257
200-
- name: 'Upload RPM file(s) to GitHub Release (github-script)'
258+
- name: "Upload RPM file(s) to GitHub Release (dry_run != 'yes')"
201259
if: ${{ github.event.inputs.dry_run != 'yes' }}
202260
uses: actions/github-script@v4
203261
env:

.github/workflows/tag_deploy.yml

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# NOTICE: **This file is maintained with puppetsync**
55
#
6-
# This file is updated automatically as part of a puppet module baseline.
6+
# This file is updated automatically as part of a standardized asset baseline.
77
#
88
# The next baseline sync will overwrite any local changes to this file!
99
#
@@ -24,16 +24,19 @@
2424
#
2525
# NOTES:
2626
#
27-
# * The CHANGLOG text is altered to remove RPM-style date headers, which don't
27+
# * The CHANGELOG text is altered to remove RPM-style date headers, which don't
2828
# render well as markdown on the GitHub release pages
2929
#
3030
---
31-
name: 'Tag: Release to GitHub & Puppet Forge'
31+
name: 'Tag: Release to GitHub w/RPMs + Puppet Forge'
3232

3333
on:
3434
push:
3535
tags:
36+
# NOTE: These filter patterns aren't actually regexes:
37+
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
3638
- '[0-9]+\.[0-9]+\.[0-9]+'
39+
- '[0-9]+\.[0-9]+\.[0-9]+\-[a-z]+[0-9]+'
3740

3841
env:
3942
PUPPET_VERSION: '~> 6'
@@ -42,7 +45,7 @@ jobs:
4245
releng-checks:
4346
name: "RELENG checks"
4447
if: github.repository_owner == 'simp'
45-
runs-on: ubuntu-18.04
48+
runs-on: ubuntu-latest
4649
steps:
4750
- name: "Assert '${{ github.ref }}' is a tag"
4851
run: '[[ "$GITHUB_REF" =~ ^refs/tags/ ]] || { echo "::error ::GITHUB_REF is not a tag: ${GITHUB_REF}"; exit 1 ; }'
@@ -66,7 +69,9 @@ jobs:
6669
name: Deploy GitHub Release
6770
needs: [ releng-checks ]
6871
if: github.repository_owner == 'simp'
69-
runs-on: ubuntu-18.04
72+
runs-on: ubuntu-latest
73+
outputs:
74+
prerelease: ${{ steps.tag-check.outputs.prerelease }}
7075
steps:
7176
- name: Checkout code
7277
uses: actions/checkout@v2
@@ -82,7 +87,19 @@ jobs:
8287
annotation="$(git for-each-ref "$GITHUB_REF" --format='%(contents)' --count=1)"
8388
annotation_title="$(echo "$annotation" | head -1)"
8489
90+
91+
if [[ "$tag" =~ ^(simp-|v)?[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta|pre|post)?([0-9]+)?)?$ ]]; then
92+
if [ -n "${BASH_REMATCH[2]}" ]; then
93+
prerelease=yes
94+
annotation_title="Pre-release of ${tag}"
95+
fi
96+
else
97+
printf '::error ::Release Tag format is not SemVer, X.Y.Z-R, X.Y.Z-<prerelease>: "%s"\n' "$RELEASE_TAG"
98+
exit 88
99+
fi
100+
85101
echo "::set-output name=tag::${tag}"
102+
echo "::set-output name=prerelease::${prerelease}"
86103
echo "::set-output name=annotation_title::${annotation_title}"
87104
88105
# Prepare annotation body as a file for the next step
@@ -104,21 +121,26 @@ jobs:
104121
tag_name: ${{ github.ref }}
105122
release_name: ${{ steps.tag-check.outputs.annotation_title }}
106123
body_path: /tmp/annotation.body
124+
prerelease: ${{ steps.tag-check.outputs.prerelease == 'yes'}}
107125
draft: false
108-
prerelease: false
109126

110127
build-and-attach-rpms:
111128
name: Trigger RPM release
112129
needs: [ create-github-release ]
113130
if: github.repository_owner == 'simp'
114-
runs-on: ubuntu-18.04
131+
runs-on: ubuntu-latest
115132
env:
116133
TARGET_REPO: ${{ github.repository }}
134+
strategy:
135+
matrix:
136+
os:
137+
- centos7
138+
- centos8
117139
steps:
118140
- name: Get tag & annotation info (${{github.ref}})
119141
id: tag-check
120142
run: echo "::set-output name=tag::${GITHUB_REF/refs\/tags\//}"
121-
- name: Trigger RPM release workflow
143+
- name: Trigger RPM release workflow (${{ matrix.os }})
122144
uses: actions/github-script@v4
123145
env:
124146
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
@@ -133,17 +155,20 @@ jobs:
133155
workflow_id: 'release_rpms.yml',
134156
ref: process.env.DEFAULT_BRANCH,
135157
inputs: {
136-
release_tag: process.env.TARGET_TAG
158+
release_tag: process.env.TARGET_TAG,
159+
clean: 'no',
160+
clobber: 'yes',
161+
build_container_os: '${{ matrix.os }}'
137162
}
138-
}).then( (result) => {
139-
console.log( `== Submitted workflow dispatch: status ${result.status}` )
163+
}).then((result) => {
164+
console.log( `== Submitted workflow dispatch to build RPMs from ${{ matrix.os }}: status ${result.status}` )
140165
})
141166
142167
deploy-to-puppet-forge:
143168
name: Deploy PuppetForge Release
144169
needs: [ create-github-release ]
145-
if: github.repository_owner == 'simp'
146-
runs-on: ubuntu-18.04
170+
if: (github.repository_owner == 'simp') && (needs.create-github-release.outputs.prerelease != 'yes')
171+
runs-on: ubuntu-latest
147172
env:
148173
PUPPETFORGE_API_TOKEN: ${{ secrets.PUPPETFORGE_API_TOKEN }}
149174
FORGE_USER_AGENT: GitHubActions-ForgeReleng-Workflow/0.4.0 (Purpose/forge-ops-for-${{ github.event.repository.name }})
@@ -160,7 +185,7 @@ jobs:
160185
bundler-cache: true
161186
- name: Build Puppet module (PDK)
162187
run: bundle exec pdk build --force
163-
- name: Deploy to Puppet Forge
188+
- name: Deploy to Puppet Forge (skipped when prerelease)
164189
run: |
165190
curl -X POST --silent --show-error --fail \
166191
--user-agent "$FORGE_USER_AGENT" \

0 commit comments

Comments
 (0)