@@ -125,8 +125,9 @@ const modifyManifest = (manifest, runTests = false) => {
125125 * @param {string } localRepoName The flatpak repository name
126126 * @param {boolean } cacheBuildDir Whether to enable caching the build directory
127127 * @param {string } cacheKey The key used to cache the build directory
128+ * @param {string } arch The CPU architecture to build for
128129 */
129- const build = async ( manifest , manifestPath , bundle , repositoryUrl , repositoryName , buildDir , localRepoName , cacheBuildDir , cacheKey ) => {
130+ const build = async ( manifest , manifestPath , bundle , repositoryUrl , repositoryName , buildDir , localRepoName , cacheBuildDir , cacheKey , arch ) => {
130131 const appId = manifest [ 'app-id' ] || manifest . id
131132 const branch = manifest . branch || core . getInput ( 'branch' ) || 'master'
132133
@@ -137,7 +138,8 @@ const build = async (manifest, manifestPath, bundle, repositoryUrl, repositoryNa
137138 '--disable-rofiles-fuse' ,
138139 `--install-deps-from=${ repositoryName } ` ,
139140 '--force-clean' ,
140- `--default-branch=${ branch } `
141+ `--default-branch=${ branch } ` ,
142+ `--arch=${ arch } `
141143 ]
142144 if ( cacheBuildDir ) {
143145 args . push ( '--ccache' )
@@ -160,6 +162,7 @@ const build = async (manifest, manifestPath, bundle, repositoryUrl, repositoryNa
160162 localRepoName ,
161163 bundle ,
162164 `--runtime-repo=${ repositoryUrl } ` ,
165+ `--arch=${ arch } ` ,
163166 appId ,
164167 branch
165168 ] )
@@ -175,9 +178,10 @@ const build = async (manifest, manifestPath, bundle, repositoryUrl, repositoryNa
175178 * @param {PathLike } manifestPath the manifest path
176179 * @param {Boolean } cacheBuildDir whether to cache the build dir or not
177180 * @param {string | undefined } cacheKey the default cache key if there are any
181+ * @param {string } arch The CPU architecture to build for
178182 * @returns {Promise<String> } the new cacheKey if none was set before
179183 */
180- const prepareBuild = async ( repositoryName , repositoryUrl , manifestPath , cacheBuildDir , cacheKey = undefined ) => {
184+ const prepareBuild = async ( repositoryName , repositoryUrl , manifestPath , cacheBuildDir , cacheKey = undefined , arch ) => {
181185 /// If the user has set a different runtime source
182186 if ( repositoryUrl !== 'https://flathub.org/repo/flathub.flatpakrepo' ) {
183187 await exec . exec ( 'flatpak' , [ 'remote-add' , '--if-not-exists' , repositoryName , repositoryUrl ] )
@@ -204,7 +208,8 @@ const prepareBuild = async (repositoryName, repositoryUrl, manifestPath, cacheBu
204208 core . info ( 'No cache was found' )
205209 }
206210 }
207- return cacheKey
211+ // Ensure the cache key is unique if we're building multiple architectures in the same job
212+ return `${ cacheKey } -${ arch } `
208213}
209214
210215/**
@@ -219,6 +224,7 @@ const prepareBuild = async (repositoryName, repositoryUrl, manifestPath, cacheBu
219224 * @param {string } localRepoName The flatpak repository name
220225 * @param {boolean } cacheBuildDir Whether to enable caching the build directory
221226 * @param {string | undefined } cacheKey the default cache key if there are any
227+ * @param {string } arch The CPU architecture to build for
222228 */
223229const run = async (
224230 manifestPath ,
@@ -229,10 +235,11 @@ const run = async (
229235 buildDir ,
230236 localRepoName ,
231237 cacheBuildDir ,
232- cacheKey = undefined
238+ cacheKey = undefined ,
239+ arch
233240) => {
234241 try {
235- cacheKey = await prepareBuild ( repositoryName , repositoryUrl , manifestPath , cacheBuildDir , cacheKey )
242+ cacheKey = await prepareBuild ( repositoryName , repositoryUrl , manifestPath , cacheBuildDir , cacheKey , arch )
236243 } catch ( err ) {
237244 core . setFailed ( `Failed to prepare the build ${ err } ` )
238245 }
@@ -243,13 +250,15 @@ const run = async (
243250 return saveManifest ( modifiedManifest , manifestPath )
244251 } )
245252 . then ( ( manifest ) => {
246- return build ( manifest , manifestPath , bundle , repositoryUrl , repositoryName , buildDir , localRepoName , cacheBuildDir , cacheKey )
253+ return build ( manifest , manifestPath , bundle , repositoryUrl , repositoryName , buildDir , localRepoName , cacheBuildDir , cacheKey , arch )
247254 } )
248255 . then ( ( ) => {
249256 core . info ( 'Uploading artifact...' )
250257 const artifactClient = artifact . create ( )
251258
252- return artifactClient . uploadArtifact ( bundle . replace ( '.flatpak' , '' ) , [ bundle ] , '.' , {
259+ // Append the arch to the bundle name to prevent conflicts in multi-arch jobs
260+ const bundleName = bundle . replace ( '.flatpak' , '' ) + `-${ arch } `
261+ return artifactClient . uploadArtifact ( bundleName , [ bundle ] , '.' , {
253262 continueOnError : false
254263 } )
255264 } )
@@ -277,6 +286,7 @@ if (require.main === module) {
277286 'flatpak_app' ,
278287 'repo' ,
279288 [ 'y' , 'yes' , 'true' , 'enabled' , true ] . includes ( core . getInput ( 'cache' ) ) ,
280- core . getInput ( 'cache-key' )
289+ core . getInput ( 'cache-key' ) ,
290+ core . getInput ( 'arch' )
281291 )
282292}
0 commit comments