Debian Codegraph @

.github/actions/package-nfpm/action.yml

raw
1 name: package-nfpm
2 description: Package module using nfpm
3 inputs:
4 nfpm_file_pattern:
5 description: The pattern of the nfpm configuration file(s)
6 required: true
7 package_extension:
8 description: The package extension (deb or rpm)
9 required: true
10 distrib:
11 description: The package distrib
12 required: true
13 version:
14 description: The package version ([major_version].[minor_version])
15 required: false
16 major_version:
17 description: The major version
18 required: false
19 minor_version:
20 description: The minor version
21 required: false
22 release:
23 description: The package release number
24 required: true
25 arch:
26 description: The package architecture
27 required: false
28 commit_hash:
29 description: The commit hash
30 required: true
31 cache_key:
32 description: The package files cache key
33 required: true
34 rpm_gpg_key:
35 description: The rpm gpg key
36 required: true
37 rpm_gpg_signing_key_id:
38 description: The rpm gpg signing key identifier
39 required: true
40 rpm_gpg_signing_passphrase:
41 description: The rpm gpg signing passphrase
42 required: true
43 stability:
44 description: "Branch stability (stable, testing, unstable, canary)"
45 required: true
46
47 runs:
48 using: composite
49
50 steps:
51 - name: Parse distrib name
52 id: parse-distrib
53 uses: ./.github/actions/parse-distrib
54 with:
55 distrib: ${{ inputs.distrib }}
56
57 - name: Import gpg key
58 env:
59 RPM_GPG_SIGNING_KEY: ${{ inputs.rpm_gpg_key }}
60 run: echo -n "$RPM_GPG_SIGNING_KEY" > key.gpg
61 shell: bash
62
63 - name: Build ${{ inputs.package_extension }} files
64 env:
65 RPM_GPG_SIGNING_KEY_ID: ${{ inputs.rpm_gpg_signing_key_id }}
66 RPM_GPG_SIGNING_PASSPHRASE: ${{ inputs.rpm_gpg_signing_passphrase }}
67 run: |
68 if [ -z ${{ inputs.version }} ]; then
69 export VERSION="${{ inputs.major_version }}.${{ inputs.minor_version }}"
70 export MAJOR_VERSION="${{ inputs.major_version }}"
71 export MINOR_VERSION="${{ inputs.minor_version }}"
72 elif [ -z ${{ inputs.major_version }} ]; then
73 export VERSION="${{ inputs.version }}"
74 export MAJOR_VERSION=$( echo $VERSION | cut -d "-" -f1 )
75 export MINOR_VERSION=$( echo $VERSION | cut -d "-" -f2 )
76 fi
77 export RELEASE="${{ inputs.release }}"
78 export ARCH="${{ inputs.arch }}"
79
80 if [ "${{ inputs.package_extension }}" = "rpm" ]; then
81 export DIST=".${{ inputs.distrib }}"
82 export APACHE_USER="apache"
83 export APACHE_GROUP="apache"
84 else
85 export DIST=""
86 if [ "${{ inputs.stability }}" == "unstable" ] || [ "${{ inputs.stability }}" == "canary" ]; then
87 export RELEASE="$RELEASE${{ steps.parse-distrib.outputs.package_distrib_separator }}${{ steps.parse-distrib.outputs.package_distrib_name }}"
88 else
89 export RELEASE="1${{ steps.parse-distrib.outputs.package_distrib_separator }}${{ steps.parse-distrib.outputs.package_distrib_name }}"
90 fi
91 export APACHE_USER="www-data"
92 export APACHE_GROUP="www-data"
93 fi
94
95 if [ -z "$MAJOR_VERSION" ]; then
96 MAJOR_LEFT=$( echo $VERSION | cut -d "." -f1 )
97 MAJOR_RIGHT=$( echo $VERSION | cut -d "-" -f1 | cut -d "." -f2 )
98 if [ "$MAJOR_RIGHT" == "04" ]; then
99 BUMP_MAJOR_LEFT="$MAJOR_LEFT"
100 BUMP_MAJOR_RIGHT="10"
101 else
102 BUMP_MAJOR_LEFT=$(( $MAJOR_LEFT + 1 ))
103 BUMP_MAJOR_RIGHT="04"
104 fi
105 export NEXT_MAJOR_VERSION="$BUMP_MAJOR_LEFT.$BUMP_MAJOR_RIGHT"
106 fi
107
108 export RPM_SIGNING_KEY_FILE="$(pwd)/key.gpg"
109 export RPM_SIGNING_KEY_ID="$RPM_GPG_SIGNING_KEY_ID"
110 export NFPM_RPM_PASSPHRASE="$RPM_GPG_SIGNING_PASSPHRASE"
111
112 for FILE in ${{ inputs.nfpm_file_pattern }}; do
113 DIRNAME=$(dirname $FILE)
114 BASENAME=$(basename $FILE)
115 cd $DIRNAME
116 sed -i "s/@APACHE_USER@/$APACHE_USER/g" $BASENAME
117 sed -i "s/@APACHE_GROUP@/$APACHE_GROUP/g" $BASENAME
118 sed -i "s/@COMMIT_HASH@/${{ inputs.commit_hash }}/g" $BASENAME
119 nfpm package --config $BASENAME --packager ${{ inputs.package_extension }}
120 cd -
121 mv $DIRNAME/*.${{ inputs.package_extension }} ./
122 done
123 shell: bash
124
125 - uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
126 with:
127 path: ./*.${{ inputs.package_extension }}
128 key: ${{ inputs.cache_key }}
129
130 # Add to your PR the label upload-artifacts to get packages as artifacts
131 - if: ${{ contains(github.event.pull_request.labels.*.name, 'upload-artifacts') }}
132 name: Upload package artifacts
133 uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
134 with:
135 name: packages-${{ inputs.distrib }}
136 path: ./*.${{ inputs.package_extension}}
137 retention-days: 1