1- name : " Publish module"
1+ # This is a generic workflow for releasing a Puppet module.
2+ # It requires that the caller sets `secrets: inherit` to ensure
3+ # that secrets are visible from steps in this workflow.
4+ name : " Module Release"
25
36on :
4- workflow_dispatch :
5-
7+ workflow_call :
8+
69jobs :
7- release :
8- uses : " puppetlabs/cat-github-actions/.github/workflows/module_release.yml@main"
9- secrets : " inherit"
10+ release :
11+ name : " Release"
12+ runs-on : " ubuntu-latest"
13+ if : github.repository_owner == 'TraGicCode'
14+
15+ steps :
16+
17+ - name : " Set up Ruby"
18+ uses : " actions/setup-ruby@v1"
19+ with :
20+ ruby-version : " 3.1"
21+
22+ - name : " Checkout"
23+ uses : " actions/checkout@v4"
24+ with :
25+ ref : " ${{ github.ref }}"
26+ clean : true
27+ fetch-depth : 0
28+
29+ - name : " Get version"
30+ id : " get_version"
31+ run : |
32+ ruby <<-EOF >> $GITHUB_OUTPUT
33+ require "json"
34+ version = JSON.parse(File.read("metadata.json"))["version"]
35+
36+ # from https://github.com/voxpupuli/metadata-json-lint/blob/b5e68049c6be58aa63263357bb0dcad8635a6829/lib/metadata-json-lint/schema.rb#L141-L150
37+ numeric = '(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' # Major . Minor . Patch
38+ pre = '(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?' # Prerelease
39+ build = '(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?' # Build
40+ full = numeric + pre + build
41+ semver_regex = /\A#{full}\Z/
42+ if version&.match?(semver_regex)
43+ puts "version=#{version}"
44+ else
45+ raise "Version #{version} is invalid. Exiting workflow."
46+ end
47+ EOF
48+
49+ - name : " PDK build"
50+ uses : " docker://puppet/pdk:nightly"
51+ with :
52+ args : " build"
53+
54+ - name : " Generate release notes"
55+ run : |
56+ export GH_HOST=github.com
57+ gh extension install chelnak/gh-changelog
58+ gh changelog get --latest > OUTPUT.md
59+ env :
60+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
61+
62+ - name : " Create release"
63+ run : |
64+ gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md
65+ env :
66+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67+
68+ - name : " Publish module"
69+ uses : " docker://puppet/pdk:nightly"
70+ with :
71+ args : ' release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force'
0 commit comments