diff --git a/.github/publish-firefox-addon.js b/.github/publish-firefox-addon.js index eb05879..c11821b 100644 --- a/.github/publish-firefox-addon.js +++ b/.github/publish-firefox-addon.js @@ -30,6 +30,8 @@ const options = { async function main() { const manifest = require('../manifest.json'); + const manifestFirefox = require('../manifest.firefox.json'); + const addonUUID = manifestFirefox.browser_specific_settings.gecko.id; const fileName = `keeweb_connect-${manifest.version}.zip` const filePath = `web-ext-artifacts/${fileName}` const fileBuffer = fs.createReadStream(filePath); @@ -58,19 +60,53 @@ async function main() { console.log('response.status:', res.status); console.log('response.body:', resData); - const uuid = resData.uuid; - - // TODO: send patch to add-ons edit endpoint OR version edit endpoint - // https://addons-server.readthedocs.io/en/latest/topics/api/addons.html#edit - // https://mozilla.github.io/addons-server/topics/api/addons.html#version-edit - const addonPatchURL = `https://addons.mozilla.org/api/v5/addons/addon/${uuid}/`; - const addonPatchPayload = { - slug: "new-slug", // what? - tags: [] // what tags? + const uploadUUID = resData.uuid; + + // Poll the upload detail endpoint until we are validated + // https://mozilla.github.io/addons-server/topics/api/addons.html#upload-detail + var validationRes; + var validationData; + var validationTries = 0; + const validationReq = new Request(`https://addons.mozilla.org/api/v5/addons/upload/${uploadUUID}/`, { + method: 'GET' + }) + validationReq.headers.append('Authorization', `JWT ${token}`); + validationReq.headers.append('Accept', 'application/json'); + + while (validationTries < 3 && !validationData?.valid) { + // Increasingly wait before checking the validation status + await new Promise(resolve => setTimeout(resolve, 60_000 * (validationTries + 1))); + + validationTries += 1; + var validationRes = await fetch(validationReq); + validationData = await validationRes.json(); + + console.log('validationData', validationData); + console.log('validationData.validation.messages', validationData.validation?.messages); } - const req = new Request(addonPatchURL, { - method: 'PATCH', - body: addonPatchPayload, + + if (!validationData?.valid) + throw new Error('Extension did not validate in time.'); + + // Send POST to add-on version create endpoint + // https://mozilla.github.io/addons-server/topics/api/addons.html#version-create + const addonVersionCreateURL = `https://addons.mozilla.org/api/v5/addons/addon/${addonUUID}/versions/`; + const addonVersionCreatePayload = { + license: 'MIT', + upload: uploadUUID + } + const addonVersionCreateReq = new Request(addonVersionCreateURL, { + method: 'POST', + body: addonVersionCreatePayload, + }) + addonVersionCreateReq.headers.append('Authorization', `JWT ${token}`); + addonVersionCreateReq.headers.append('Accept', 'application/json'); + fetch(addonVersionCreateReq).then(async (res) => { + if (!res.ok) + throw new Error(`HTTP error! status: ${res.status}, body: `, resData); + + console.log('response.status:', res.status); + console.log('response.body:', resData); }) //TODO do we need to submit source code? diff --git a/.github/workflows/publish-firefox.yml b/.github/workflows/publish-firefox.yml index 4353c60..af478bb 100644 --- a/.github/workflows/publish-firefox.yml +++ b/.github/workflows/publish-firefox.yml @@ -27,14 +27,14 @@ jobs: run: | npm run build-firefox npx web-ext build -s dist/firefox - - name: Sign - id: sign - env: - WEB_EXT_API_KEY: ${{ vars.FIREFOX_API_KEY }} - WEB_EXT_API_SECRET: ${{ secrets.FIREFOX_API_SECRET }} - run: | - npx web-ext sign --source-dir=./dist/firefox - echo "xpi_filepath=$(ls web-ext-artifacts/*.xpi)" >> "$GITHUB_OUTPUT" + # - name: Sign + # id: sign + # env: + # WEB_EXT_API_KEY: ${{ vars.FIREFOX_API_KEY }} + # WEB_EXT_API_SECRET: ${{ secrets.FIREFOX_API_SECRET }} + # run: | + # npx web-ext sign --source-dir=./dist/firefox + # echo "xpi_filepath=$(ls web-ext-artifacts/*.xpi)" >> "$GITHUB_OUTPUT" - name: Publish env: WEB_EXT_API_KEY: ${{ vars.FIREFOX_API_KEY }} diff --git a/manifest.json b/manifest.json index 61f6532..b3f6234 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "KeeWeb Connect", - "version": "0.3.7.11", + "version": "0.3.7.13", "manifest_version": 2, "description": "__MSG_description__", "icons": {