From 22fe702b83062b8848efc4a471ca502ffc651212 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 7 Mar 2023 15:53:53 +0000 Subject: [PATCH] Include changelogs in deb package (#563) * Initial attempt at custom Debian changelogs * Iterate * Quotes... * Iterate * facepalm * Iterate * Remove reundant line * Ifs * Test * Iterate * Iterate * Brackets * inconsistent? * Update build_and_test.yaml * Update build_and_test.yaml --- .github/workflows/build_and_deploy.yaml | 3 +- .github/workflows/build_and_test.yaml | 1 + .github/workflows/build_linux.yaml | 22 +++++-- .github/workflows/build_prepare.yaml | 75 ++++++++++++++++------- element.io/release/conf_distributions | 81 ------------------------- scripts/generate-builder-config.ts | 67 ++++++-------------- 6 files changed, 90 insertions(+), 159 deletions(-) delete mode 100644 element.io/release/conf_distributions diff --git a/.github/workflows/build_and_deploy.yaml b/.github/workflows/build_and_deploy.yaml index 7744910..9d5488a 100644 --- a/.github/workflows/build_and_deploy.yaml +++ b/.github/workflows/build_and_deploy.yaml @@ -49,7 +49,7 @@ jobs: with: config: element.io/${{ inputs.mode || 'nightly' }} version: ${{ inputs.mode == 'release' && '' || 'develop' }} - calculate-nightly-versions: ${{ inputs.mode != 'release' }} + nightly: ${{ inputs.mode != 'release' }} secrets: CF_R2_ACCESS_KEY_ID: ${{ secrets.CF_R2_ACCESS_KEY_ID }} CF_R2_TOKEN: ${{ secrets.CF_R2_TOKEN }} @@ -98,6 +98,7 @@ jobs: name: Linux uses: ./.github/workflows/build_linux.yaml with: + config: element.io/${{ inputs.mode || 'nightly' }} sqlcipher: system version: ${{ needs.prepare.outputs.linux-version }} diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 451fc5a..1836402 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -31,6 +31,7 @@ jobs: matrix: sqlcipher: [system, static] with: + config: ${{ github.event.pull_request.base.ref == 'develop' && 'element.io/nightly' || 'element.io/release' }} sqlcipher: ${{ matrix.sqlcipher }} macos: diff --git a/.github/workflows/build_linux.yaml b/.github/workflows/build_linux.yaml index 5d58924..033cea6 100644 --- a/.github/workflows/build_linux.yaml +++ b/.github/workflows/build_linux.yaml @@ -4,6 +4,10 @@ on: workflow_call: inputs: + config: + type: string + required: true + description: "The config directory to use" version: type: string required: false @@ -60,16 +64,26 @@ jobs: run: | echo "config-args=--nightly '${{ inputs.version }}'" >> $GITHUB_OUTPUT - - name: Generate debian control file + - name: Generate debian files and arguments + id: debian run: | - cp element.io/${{ inputs.version && 'nightly' || 'release' }}/control.template debcontrol - INPUT_VERSION="${{ inputs.version }}" + if [ -f changelog.Debian ]; then + echo "config-args=--deb-changelog changelog.Debian" >> $GITHUB_OUTPUT + fi + + cp "$DIR/control.template" debcontrol VERSION=${INPUT_VERSION:-$(cat package.json | jq -r .version)} echo "Version: $VERSION" >> debcontrol + env: + DIR: ${{ inputs.config }} + INPUT_VERSION: ${{ inputs.version }} - name: Build App run: | - scripts/generate-builder-config.ts ${{ steps.nightly.outputs.config-args }} --deb-custom-control=debcontrol + scripts/generate-builder-config.ts \ + ${{ steps.nightly.outputs.config-args }} \ + ${{ steps.debian.outputs.config-args }} \ + --deb-custom-control=debcontrol yarn build --publish never -l --config electron-builder.json - name: Upload Artifacts diff --git a/.github/workflows/build_prepare.yaml b/.github/workflows/build_prepare.yaml index a0c2430..388e3f4 100644 --- a/.github/workflows/build_prepare.yaml +++ b/.github/workflows/build_prepare.yaml @@ -10,37 +10,38 @@ on: type: string required: false description: "The version tag to fetch, or 'develop', will pick automatically if not passed" - calculate-nightly-versions: - type: string + nightly: + type: boolean required: false - description: "Whether to calculate the version strings new Nightly builds should use" + default: false + description: "Whether the build is a Nightly and to calculate the version strings new builds should use" secrets: - # Required if `calculate-nightly-versions` is set + # Required if `nightly` is set CF_R2_ACCESS_KEY_ID: required: false - # Required if `calculate-nightly-versions` is set + # Required if `nightly` is set CF_R2_TOKEN: required: false - # Required if `calculate-nightly-versions` is set + # Required if `nightly` is set CF_R2_S3_API: required: false outputs: macos-version: - description: "The version string the next macOS Nightly should use, only output for calculate-nightly-versions" + description: "The version string the next macOS Nightly should use, only output for nightly" value: ${{ jobs.prepare.outputs.macos-version }} linux-version: - description: "The version string the next Linux Nightly should use, only output for calculate-nightly-versions" + description: "The version string the next Linux Nightly should use, only output for nightly" value: ${{ jobs.prepare.outputs.linux-version }} win32-x64-version: - description: "The version string the next Windows x64 Nightly should use, only output for calculate-nightly-versions" + description: "The version string the next Windows x64 Nightly should use, only output for nightly" value: ${{ jobs.prepare.outputs.win32-x64-version }} win32-x86-version: - description: "The version string the next Windows x86 Nightly should use, only output for calculate-nightly-versions" + description: "The version string the next Windows x86 Nightly should use, only output for nightly" value: ${{ jobs.prepare.outputs.win32-x86-version }} jobs: prepare: name: Prepare - environment: ${{ inputs.calculate-nightly-versions && 'packages.element.io' || '' }} + environment: ${{ inputs.nightly && 'packages.element.io' || '' }} runs-on: ubuntu-latest outputs: macos-version: ${{ steps.versions.outputs.macos }} @@ -66,19 +67,9 @@ jobs: yarn run --silent electron --version > electronVersion cat package.json | jq -c .hakDependencies > hakDependencies.json - - uses: actions/upload-artifact@v3 - with: - name: webapp - retention-days: 1 - path: | - webapp.asar - package.json - electronVersion - hakDependencies.json - - - name: Calculate Nightly versions + - name: "[Nightly] Calculate versions" id: versions - if: inputs.calculate-nightly-versions + if: inputs.nightly run: | MACOS=$(aws s3 cp s3://$R2_BUCKET/nightly/update/macos/releases.json - --endpoint-url $R2_URL --region auto | jq -r .currentRelease) echo "macos=$(scripts/generate-nightly-version.ts --latest $MACOS)" >> $GITHUB_OUTPUT @@ -96,3 +87,41 @@ jobs: # XXX: UPDATE THIS BEFORE WHEN GOING LIVE R2_BUCKET: "packages-element-io-test" R2_URL: ${{ secrets.CF_R2_S3_API }} + + - name: Check version + id: package + run: | + echo "version=$(cat package.json | jq -r .version)" >> $GITHUB_OUTPUT + + - name: "[Release] Fetch release" + id: release + if: ${{ !inputs.nightly && inputs.version != 'develop' }} + uses: cardinalby/git-get-release-action@cedef2faf69cb7c55b285bad07688d04430b7ada # v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + tag: v${{ steps.package.outputs.version }} + + - name: "[Release] Write changelog" + if: ${{ !inputs.nightly && inputs.version != 'develop' }} + run: | + TIME=$(date -d "$PUBLISHED_AT" -R) + echo "element-desktop ($VERSION) default; urgency=medium" >> changelog.Debian + echo "$BODY" | sed 's/^##/\n */g;s/^\*/ */g' | perl -pe 's/\[.+?]\((.+?)\)/\1/g' >> changelog.Debian + echo "" >> changelog.Debian + echo " -- ${{ github.actor }} $TIME" >> changelog.Debian + env: + VERSION: v${{ steps.package.outputs.version }} + BODY: ${{ steps.release.outputs.body }} + PUBLISHED_AT: ${{ steps.release.outputs.published_at }} + + - uses: actions/upload-artifact@v3 + with: + name: webapp + retention-days: 1 + path: | + webapp.asar + package.json + electronVersion + hakDependencies.json + changelog.Debian diff --git a/element.io/release/conf_distributions b/element.io/release/conf_distributions deleted file mode 100644 index 37ee09f..0000000 --- a/element.io/release/conf_distributions +++ /dev/null @@ -1,81 +0,0 @@ -Origin: riot.im -Codename: default -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Suite: oldoldstable -Codename: jessie -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Suite: oldstable -Codename: stretch -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Suite: stable -Codename: buster -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Suite: testing -Codename: bullseye -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Suite: unstable -Codename: sid -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Codename: xenial -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Codename: bionic -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Codename: cosmic -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Codename: disco -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal - -Origin: riot.im -Codename: eoan -Architectures: amd64 i386 source -Components: main -SignWith: D7B0B66941D01538 -Tracking: minimal diff --git a/scripts/generate-builder-config.ts b/scripts/generate-builder-config.ts index eb98b7f..34d21c6 100755 --- a/scripts/generate-builder-config.ts +++ b/scripts/generate-builder-config.ts @@ -15,6 +15,7 @@ import parseArgs from "minimist"; import fsProm from "fs/promises"; import * as os from "os"; +import { Configuration } from "app-builder-lib"; const ELECTRON_BUILDER_CFG_FILE = "electron-builder.json"; @@ -26,53 +27,14 @@ const argv = parseArgs<{ "signtool-thumbprint"?: string; "signtool-subject-name"?: string; "deb-custom-control"?: string; + "deb-changelog"?: string; }>(process.argv.slice(2), { - string: ["nightly", "deb-custom-control", "signtool-thumbprint", "signtool-subject-name"], + string: ["nightly", "deb-custom-control", "deb-changelog", "signtool-thumbprint", "signtool-subject-name"], }); -interface File { - from: string; - to: string; -} +type DeepWriteable = { -readonly [P in keyof T]: DeepWriteable }; -interface PackageBuild { - appId: string; - asarUnpack: string; - files: Array; - extraResources: Array; - linux: { - target: string; - category: string; - maintainer: string; - desktop: { - StartupWMClass: string; - }; - }; - mac: { - category: string; - darkModeSupport: boolean; - }; - win: { - target: { - target: string; - }; - sign?: string; - signingHashAlgorithms?: string[]; - certificateSubjectName?: string; - certificateSha1?: string; - }; - deb?: { - fpm?: string[]; - }; - directories: { - output: string; - }; - afterPack: string; - afterSign: string; - protocols: Array<{ - name: string; - schemes: string[]; - }>; +interface PackageBuild extends DeepWriteable> { extraMetadata?: { productName?: string; name?: string; @@ -114,10 +76,10 @@ async function main(): Promise { } if (argv["signtool-thumbprint"] && argv["signtool-subject-name"]) { - delete cfg.win.sign; - cfg.win.signingHashAlgorithms = ["sha256"]; - cfg.win.certificateSubjectName = argv["signtool-subject-name"]; - cfg.win.certificateSha1 = argv["signtool-thumbprint"]; + delete cfg.win!.sign; + cfg.win!.signingHashAlgorithms = ["sha256"]; + cfg.win!.certificateSubjectName = argv["signtool-subject-name"]; + cfg.win!.certificateSha1 = argv["signtool-thumbprint"]; } if (os.platform() === "linux") { @@ -125,10 +87,15 @@ async function main(): Promise { // https://github.com/vector-im/element-web/issues/13171 cfg.extraMetadata!.productName = cfg.extraMetadata!.productName!.replace(/ /g, "-"); + cfg.deb = { + fpm: [], + }; + if (argv["deb-custom-control"]) { - cfg.deb = { - fpm: [`--deb-custom-control=${argv["deb-custom-control"]}`], - }; + cfg.deb.fpm!.push(`--deb-custom-control=${argv["deb-custom-control"]}`); + } + if (argv["deb-changelog"]) { + cfg.deb.fpm!.push(`--deb-changelog=${argv["deb-changelog"]}`); } }