Skip to content

Commit

Permalink
Use a configuration object
Browse files Browse the repository at this point in the history
Makes things much simpler to track & simplifies the code
  • Loading branch information
bilelmoussaoui committed Apr 2, 2023
1 parent 8326776 commit 9541860
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 316 deletions.
48 changes: 26 additions & 22 deletions flat-manager/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4090,38 +4090,47 @@ var __webpack_exports__ = {};
const core = __nccwpck_require__(699)
const exec = __nccwpck_require__(922)

// FIXME: get this from the outputs of the flatpak-builder action
const LOCAL_REPO_NAME = 'repo'
class Configuration {
constructor () {
this.repository = core.getInput('repository')
this.flatManagerUrl = core.getInput('flat-manager-url')
this.token = core.getInput('token')
this.endOfLife = core.getInput('end-of-life')
this.endOfLifeRebase = core.getInput('end-of-life-rebase')
// FIXME: get this from the outputs of the flatpak-builder action
this.localRepoName = 'repo'
}
}

const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
const run = (config) => {
exec.exec('flatpak', [
'build-update-repo',
'--generate-static-deltas',
LOCAL_REPO_NAME
config.localRepoName
])
.then(async () => {
let buildId = ''
let args = [
'--token',
token
config.token
]

if (endOfLife) {
args.push_back(`--end-of-life=${endOfLife}`)
if (config.endOfLife) {
args.push_back(`--end-of-life=${config.endOfLife}`)
}

if (endOfLifeRebase) {
if (!endOfLife) {
if (config.endOfLifeRebase) {
if (!config.endOfLife) {
throw Error('end-of-life has to be set if you want to use end-of-life-rebase')
}

args.push_back(`--end-of-life-rebase=${endOfLifeRebase}`)
args.push_back(`--end-of-life-rebase=${config.endOfLifeRebase}`)
}

args = args.concat([
'create',
flatManagerUrl,
repository
config.flatManagerUrl,
config.repository
])

const exitCode = await exec.exec('flat-manager-client', args, {
Expand All @@ -4139,20 +4148,20 @@ const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
.then(async (buildId) => {
await exec.exec('flat-manager-client', [
'--token',
token,
config.token,
'push',
'--commit',
'--publish',
'--wait',
buildId,
LOCAL_REPO_NAME
config.localRepoName
])
return buildId
})
.then(async (buildId) => {
await exec.exec('flat-manager-client', [
'--token',
token,
config.token,
'purge',
buildId
])
Expand All @@ -4163,13 +4172,8 @@ const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
}

if (require.main === require.cache[eval('__filename')]) {
run(
core.getInput('repository'),
core.getInput('flat-manager-url'),
core.getInput('token'),
core.getInput('end-of-life'),
core.getInput('end-of-life-rebase')
)
const config = new Configuration()
run(config)
}

})();
Expand Down
48 changes: 26 additions & 22 deletions flat-manager/index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
const core = require('@actions/core')
const exec = require('@actions/exec')

// FIXME: get this from the outputs of the flatpak-builder action
const LOCAL_REPO_NAME = 'repo'
class Configuration {
constructor () {
this.repository = core.getInput('repository')
this.flatManagerUrl = core.getInput('flat-manager-url')
this.token = core.getInput('token')
this.endOfLife = core.getInput('end-of-life')
this.endOfLifeRebase = core.getInput('end-of-life-rebase')
// FIXME: get this from the outputs of the flatpak-builder action
this.localRepoName = 'repo'
}
}

const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
const run = (config) => {
exec.exec('flatpak', [
'build-update-repo',
'--generate-static-deltas',
LOCAL_REPO_NAME
config.localRepoName
])
.then(async () => {
let buildId = ''
let args = [
'--token',
token
config.token
]

if (endOfLife) {
args.push_back(`--end-of-life=${endOfLife}`)
if (config.endOfLife) {
args.push_back(`--end-of-life=${config.endOfLife}`)
}

if (endOfLifeRebase) {
if (!endOfLife) {
if (config.endOfLifeRebase) {
if (!config.endOfLife) {
throw Error('end-of-life has to be set if you want to use end-of-life-rebase')
}

args.push_back(`--end-of-life-rebase=${endOfLifeRebase}`)
args.push_back(`--end-of-life-rebase=${config.endOfLifeRebase}`)
}

args = args.concat([
'create',
flatManagerUrl,
repository
config.flatManagerUrl,
config.repository
])

const exitCode = await exec.exec('flat-manager-client', args, {
Expand All @@ -50,20 +59,20 @@ const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
.then(async (buildId) => {
await exec.exec('flat-manager-client', [
'--token',
token,
config.token,
'push',
'--commit',
'--publish',
'--wait',
buildId,
LOCAL_REPO_NAME
config.localRepoName
])
return buildId
})
.then(async (buildId) => {
await exec.exec('flat-manager-client', [
'--token',
token,
config.token,
'purge',
buildId
])
Expand All @@ -74,11 +83,6 @@ const run = (repository, flatManagerUrl, token, endOfLife, endOfLifeRebase) => {
}

if (require.main === module) {
run(
core.getInput('repository'),
core.getInput('flat-manager-url'),
core.getInput('token'),
core.getInput('end-of-life'),
core.getInput('end-of-life-rebase')
)
const config = new Configuration()
run(config)
}
1 change: 1 addition & 0 deletions flat-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"eslint": "^8.37.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.5.0"
Expand Down
43 changes: 42 additions & 1 deletion flat-manager/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,13 @@ buffer-from@^1.0.0:
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==

builtins@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/builtins/-/builtins-5.0.1.tgz#87f6db9ab0458be728564fa81d876d8d74552fa9"
integrity sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==
dependencies:
semver "^7.0.0"

call-bind@^1.0.0, call-bind@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c"
Expand Down Expand Up @@ -1297,6 +1304,14 @@ eslint-plugin-es@^3.0.0:
eslint-utils "^2.0.0"
regexpp "^3.0.0"

eslint-plugin-es@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-es/-/eslint-plugin-es-4.1.0.tgz#f0822f0c18a535a97c3e714e89f88586a7641ec9"
integrity sha512-GILhQTnjYE2WorX5Jyi5i4dz5ALWxBIdQECVQavL6s7cI76IZTDWleTHkxz/QT3kvcs2QlGHvKLYsSlPOlPXnQ==
dependencies:
eslint-utils "^2.0.0"
regexpp "^3.0.0"

eslint-plugin-import@^2.22.1:
version "2.27.5"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz#876a6d03f52608a3e5bb439c2550588e51dd6c65"
Expand All @@ -1318,6 +1333,20 @@ eslint-plugin-import@^2.22.1:
semver "^6.3.0"
tsconfig-paths "^3.14.1"

eslint-plugin-n@^15.7.0:
version "15.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-n/-/eslint-plugin-n-15.7.0.tgz#e29221d8f5174f84d18f2eb94765f2eeea033b90"
integrity sha512-jDex9s7D/Qial8AGVIHq4W7NswpUD5DPDL2RH8Lzd9EloWUuvUkHfv4FRLMipH5q2UtyurorBkPeNi1wVWNh3Q==
dependencies:
builtins "^5.0.1"
eslint-plugin-es "^4.1.0"
eslint-utils "^3.0.0"
ignore "^5.1.1"
is-core-module "^2.11.0"
minimatch "^3.1.2"
resolve "^1.22.1"
semver "^7.3.8"

eslint-plugin-node@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz#c95544416ee4ada26740a30474eefc5402dc671d"
Expand Down Expand Up @@ -1350,11 +1379,23 @@ eslint-utils@^2.0.0:
dependencies:
eslint-visitor-keys "^1.1.0"

eslint-utils@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-3.0.0.tgz#8aebaface7345bb33559db0a1f13a1d2d48c3672"
integrity sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==
dependencies:
eslint-visitor-keys "^2.0.0"

eslint-visitor-keys@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==

eslint-visitor-keys@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==

eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz#c7f0f956124ce677047ddbc192a68f999454dedc"
Expand Down Expand Up @@ -2798,7 +2839,7 @@ semver@^6.0.0, semver@^6.1.0, semver@^6.3.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.3.5:
semver@^7.0.0, semver@^7.3.5, semver@^7.3.8:
version "7.3.8"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798"
integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==
Expand Down
Loading

0 comments on commit 9541860

Please sign in to comment.