|
| 1 | +name: git-artifacts |
| 2 | +run-name: Build git-artifacts (${{ inputs.architecture }}) |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + artifacts: |
| 8 | + description: 'Optionally restrict what artifacts to build (portable, installer, etc.). Separate artifacts with spaces' |
| 9 | + required: false |
| 10 | + ref: |
| 11 | + description: 'Optionally override which branch to build' |
| 12 | + required: false |
| 13 | + default: main |
| 14 | + repository: |
| 15 | + description: 'Optionally override from where to fetch the specified ref' |
| 16 | + required: false |
| 17 | + default: git-for-windows/git |
| 18 | + architecture: |
| 19 | + type: choice |
| 20 | + description: 'Architecture to build' |
| 21 | + required: true |
| 22 | + options: |
| 23 | + - x86_64 |
| 24 | + - i686 |
| 25 | + - aarch64 |
| 26 | + bundle_artifacts_workflow_run_id: |
| 27 | + description: 'Workflow run ID from bundle-artifacts pipeline' |
| 28 | + required: false |
| 29 | + |
| 30 | +env: |
| 31 | + GPG_OPTIONS: "--batch --yes --no-tty --list-options no-show-photos --verify-options no-show-photos --pinentry-mode loopback" |
| 32 | + HOME: "${{github.workspace}}\\home" |
| 33 | + USERPROFILE: "${{github.workspace}}\\home" |
| 34 | + ARTIFACTS_TO_BUILD: "${{github.event.inputs.artifacts}}" |
| 35 | + REPOSITORY: "${{github.event.inputs.repository}}" |
| 36 | + REF: "${{github.event.inputs.ref}}" |
| 37 | + ARCHITECTURE: "${{github.event.inputs.architecture}}" |
| 38 | + BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID: "${{github.event.inputs.bundle_artifacts_workflow_run_id}}" |
| 39 | + |
| 40 | +defaults: |
| 41 | + run: |
| 42 | + shell: bash |
| 43 | + |
| 44 | +jobs: |
| 45 | + pkg: |
| 46 | + runs-on: ${{ github.event.inputs.architecture == 'aarch64' && fromJSON('["Windows", "ARM64"]') || 'windows-latest' }} |
| 47 | + outputs: |
| 48 | + artifact_matrix: ${{steps.artifact-build-matrix.outputs.matrix}} |
| 49 | + msystem: ${{steps.configure-environment.outputs.MSYSTEM}} |
| 50 | + mingw_package_prefix: ${{steps.configure-environment.outputs.MINGW_PACKAGE_PREFIX}} |
| 51 | + sdk_repo_arch: ${{steps.configure-environment.outputs.SDK_REPO_ARCH}} |
| 52 | + steps: |
| 53 | + - name: Configure environment |
| 54 | + id: configure-environment |
| 55 | + run: | |
| 56 | + case "$ARCHITECTURE" in |
| 57 | + x86_64) |
| 58 | + MSYSTEM=MINGW64 |
| 59 | + MINGW_PREFIX=/mingw64 |
| 60 | + MINGW_PACKAGE_PREFIX=mingw-w64-x86_64 |
| 61 | + SDK_REPO_ARCH=64 |
| 62 | + ;; |
| 63 | + i686) |
| 64 | + MSYSTEM=MINGW32 |
| 65 | + MINGW_PREFIX=/mingw32 |
| 66 | + MINGW_PACKAGE_PREFIX=mingw-w64-i686 |
| 67 | + SDK_REPO_ARCH=32 |
| 68 | + ;; |
| 69 | + aarch64) |
| 70 | + MSYSTEM=CLANGARM64 |
| 71 | + MINGW_PREFIX=/clangarm64 |
| 72 | + MINGW_PACKAGE_PREFIX=mingw-w64-clang-aarch64 |
| 73 | + SDK_REPO_ARCH=arm64 |
| 74 | + ;; |
| 75 | + *) |
| 76 | + echo "Unhandled architecture: $ARCHITECTURE" |
| 77 | + exit 1 |
| 78 | + ;; |
| 79 | + esac |
| 80 | + echo "MSYSTEM=$MSYSTEM" >> $GITHUB_ENV |
| 81 | + echo "MSYSTEM=$MSYSTEM" >> $GITHUB_OUTPUT |
| 82 | + echo "MINGW_PREFIX=$MINGW_PREFIX" >> $GITHUB_ENV |
| 83 | + echo "MINGW_PACKAGE_PREFIX=$MINGW_PACKAGE_PREFIX" >> $GITHUB_ENV |
| 84 | + echo "MINGW_PACKAGE_PREFIX=$MINGW_PACKAGE_PREFIX" >> $GITHUB_OUTPUT |
| 85 | + echo "SDK_REPO_ARCH=$SDK_REPO_ARCH" >> $GITHUB_OUTPUT |
| 86 | + echo "ARTIFACTS_TO_BUILD=$(test -n "$ARTIFACTS_TO_BUILD" && echo $ARTIFACTS_TO_BUILD || \ |
| 87 | + echo "installer portable archive mingit$(test "$ARCHITECTURE" = aarch64 || echo ' mingit-busybox')")" >> $GITHUB_ENV |
| 88 | + - name: Configure user |
| 89 | + run: |
| 90 | + USER_NAME="${{github.actor}}" && |
| 91 | + USER_EMAIL="${{github.actor}}@users.noreply.github.com" && |
| 92 | + mkdir "$HOME" && |
| 93 | + git config --global user.name "$USER_NAME" && |
| 94 | + git config --global user.email "$USER_EMAIL" && |
| 95 | + echo "PACKAGER=$USER_NAME <$USER_EMAIL>" >> $GITHUB_ENV |
| 96 | + - uses: git-for-windows/setup-git-for-windows-sdk@v1 |
| 97 | + with: |
| 98 | + flavor: build-installers |
| 99 | + architecture: ${{env.architecture}} |
| 100 | + - name: clone git-for-windows-automation |
| 101 | + run: git clone --single-branch -b $GITHUB_REF_NAME https://github.com/git-for-windows/git-for-windows-automation |
| 102 | + - uses: actions/github-script@v6 |
| 103 | + id: artifact-build-matrix |
| 104 | + name: Create artifact build matrix |
| 105 | + with: |
| 106 | + script: | |
| 107 | + core.info('Preparing artifact build matrix...') |
| 108 | + const createArtifactsMatrix = require('./git-for-windows-automation/create-artifacts-matrix') |
| 109 | + createArtifactsMatrix(core, process.env.ARTIFACTS_TO_BUILD, process.env.ARCHITECTURE) |
| 110 | + - uses: actions/github-script@v6 |
| 111 | + id: get-bundle-artifacts-url |
| 112 | + name: Get bundle-artifacts download URL |
| 113 | + with: |
| 114 | + script: | |
| 115 | + const getArtifact = require('./git-for-windows-automation/get-bundle-artifacts-artifact') |
| 116 | + const workflowId = process.env.BUNDLE_ARTIFACTS_WORKFLOW_RUN_ID |
| 117 | + core.info('Getting download URL for bundle-artifacts...') |
| 118 | + await getArtifact(github, context, core, workflowId) |
| 119 | + - name: Download bundle-artifacts zip |
| 120 | + run: | |
| 121 | + mkdir bundle-artifacts |
| 122 | + curl -o bundle-artifacts.zip "${{steps.get-bundle-artifacts-url.outputs.downloadUrl}}" |
| 123 | + unzip bundle-artifacts.zip -d bundle-artifacts |
| 124 | + echo "GIT_VERSION=$(cat bundle-artifacts/next_version)" >> $GITHUB_ENV |
| 125 | + - name: Re-publish bundle-artifacts so the next job can easily use it |
| 126 | + uses: actions/upload-artifact@v3 |
| 127 | + with: |
| 128 | + name: bundle-artifacts |
| 129 | + path: bundle-artifacts |
| 130 | + - name: Clone and update build-extra |
| 131 | + run: | |
| 132 | + d=/usr/src/build-extra && |
| 133 | + if test ! -d $d/.git |
| 134 | + then |
| 135 | + git clone --single-branch -b main https://github.com/git-for-windows/build-extra $d |
| 136 | + else |
| 137 | + git -C $d fetch https://github.com/git-for-windows/build-extra main && |
| 138 | + git -C $d switch -C main FETCH_HEAD |
| 139 | + fi && |
| 140 | + git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main |
| 141 | + - name: Check out git/git |
| 142 | + shell: bash |
| 143 | + run: | |
| 144 | + git -c init.defaultBranch=main init && |
| 145 | + git remote add -f origin https://github.com/git-for-windows/git && |
| 146 | + git fetch --tags bundle-artifacts/git.bundle $(cat bundle-artifacts/next_version) && |
| 147 | + git reset --hard $(cat bundle-artifacts/next_version) |
| 148 | + - name: Prepare home directory for code-signing |
| 149 | + env: |
| 150 | + CODESIGN_P12: ${{secrets.CODESIGN_P12}} |
| 151 | + CODESIGN_PASS: ${{secrets.CODESIGN_PASS}} |
| 152 | + if: env.CODESIGN_P12 != '' && env.CODESIGN_PASS != '' |
| 153 | + run: | |
| 154 | + cd home && |
| 155 | + mkdir -p .sig && |
| 156 | + echo -n "$CODESIGN_P12" | tr % '\n' | base64 -d >.sig/codesign.p12 && |
| 157 | + echo -n "$CODESIGN_PASS" >.sig/codesign.pass |
| 158 | + git config --global alias.signtool '!sh "/usr/src/build-extra/signtool.sh"' |
| 159 | + - name: Prepare home directory for GPG signing |
| 160 | + if: env.GPGKEY != '' |
| 161 | + run: | |
| 162 | + echo '${{secrets.PRIVGPGKEY}}' | tr % '\n' | gpg $GPG_OPTIONS --import && |
| 163 | + info="$(gpg --list-keys --with-colons "${GPGKEY%% *}" | cut -d : -f 1,10 | sed -n '/^uid/{s|uid:||p;q}')" && |
| 164 | + git config --global user.name "${info% <*}" && |
| 165 | + git config --global user.email "<${info#*<}" |
| 166 | + env: |
| 167 | + GPGKEY: ${{secrets.GPGKEY}} |
| 168 | + - name: Cache ${{env.MINGW_PACKAGE_PREFIX}}-git |
| 169 | + id: cache-git-pkg |
| 170 | + uses: actions/cache@v3 |
| 171 | + with: |
| 172 | + path: artifacts |
| 173 | + key: pkg-${{env.GIT_VERSION}}-${{env.ARCHITECTURE}} |
| 174 | + - name: Build ${{env.MINGW_PACKAGE_PREFIX}}-git |
| 175 | + if: steps.cache-git-pkg.outputs.cache-hit != 'true' |
| 176 | + env: |
| 177 | + GPGKEY: "${{secrets.GPGKEY}}" |
| 178 | + run: | |
| 179 | + set -x |
| 180 | + BUILD_SRC=$(test x86_64 != "$ARCHITECTURE" || echo "--build-src-pkg") |
| 181 | + # Make sure that there is a `/usr/bin/git` that can be used by `makepkg-mingw` |
| 182 | + printf '#!/bin/sh\n\nexec '$MINGW_PREFIX'/bin/git.exe "$@"\n' >/usr/bin/git && |
| 183 | + /usr/src/build-extra/please.sh build-mingw-w64-git --only-$ARCHITECTURE $BUILD_SRC -o artifacts HEAD && |
| 184 | + cp bundle-artifacts/ver artifacts/ && |
| 185 | + if test -n "$GPGKEY" |
| 186 | + then |
| 187 | + for tar in artifacts/*.tar* |
| 188 | + do |
| 189 | + /usr/src/build-extra/gnupg-with-gpgkey.sh --detach-sign --no-armor $tar |
| 190 | + done |
| 191 | + fi && |
| 192 | + b=$PWD/artifacts && |
| 193 | + version=$(cat bundle-artifacts/next_version) && |
| 194 | + (cd /usr/src/MINGW-packages/mingw-w64-git && |
| 195 | + cp PKGBUILD.$version PKGBUILD && |
| 196 | + git commit -s -m "mingw-w64-git: new version ($version)" PKGBUILD && |
| 197 | + git bundle create "$b"/MINGW-packages.bundle origin/main..main) |
| 198 | + - name: Publish ${{env.MINGW_PACKAGE_PREFIX}}-git |
| 199 | + uses: actions/upload-artifact@v3 |
| 200 | + with: |
| 201 | + name: pkg-${{env.ARCHITECTURE}} |
| 202 | + path: artifacts |
| 203 | + artifacts: |
| 204 | + runs-on: ${{ github.event.inputs.architecture == 'aarch64' && fromJSON('["Windows", "ARM64"]') || 'windows-latest' }} |
| 205 | + needs: pkg |
| 206 | + env: |
| 207 | + MSYSTEM: ${{ needs.pkg.outputs.msystem }} |
| 208 | + MINGW_PACKAGE_PREFIX: ${{ needs.pkg.outputs.mingw_package_prefix }} |
| 209 | + SDK_REPO_ARCH: ${{ needs.pkg.outputs.sdk_repo_arch }} |
| 210 | + strategy: |
| 211 | + fail-fast: false |
| 212 | + matrix: ${{ fromJSON(needs.pkg.outputs.artifact_matrix) }} |
| 213 | + steps: |
| 214 | + - name: Download pkg-${{env.ARCHITECTURE}} |
| 215 | + uses: actions/download-artifact@v3 |
| 216 | + with: |
| 217 | + name: pkg-${{env.ARCHITECTURE}} |
| 218 | + path: pkg-${{env.ARCHITECTURE}} |
| 219 | + - name: Download bundle-artifacts |
| 220 | + uses: actions/download-artifact@v3 |
| 221 | + with: |
| 222 | + name: bundle-artifacts |
| 223 | + path: bundle-artifacts |
| 224 | + - uses: git-for-windows/setup-git-for-windows-sdk@v1 |
| 225 | + with: |
| 226 | + flavor: build-installers |
| 227 | + architecture: ${{env.ARCHITECTURE}} |
| 228 | + - name: Clone and update build-extra |
| 229 | + run: | |
| 230 | + d=/usr/src/build-extra && |
| 231 | + if test ! -d $d/.git |
| 232 | + then |
| 233 | + git clone --single-branch -b main https://github.com/git-for-windows/build-extra $d |
| 234 | + else |
| 235 | + git -C $d fetch https://github.com/git-for-windows/build-extra main && |
| 236 | + git -C $d switch -C main FETCH_HEAD |
| 237 | + fi && |
| 238 | + git -C $d pull "$PWD"/bundle-artifacts/build-extra.bundle main |
| 239 | + - name: Prepare home directory for code-signing |
| 240 | + env: |
| 241 | + CODESIGN_P12: ${{secrets.CODESIGN_P12}} |
| 242 | + CODESIGN_PASS: ${{secrets.CODESIGN_PASS}} |
| 243 | + if: (matrix.artifact.name == 'installer' || matrix.artifact.name == 'portable') && env.CODESIGN_P12 != '' && env.CODESIGN_PASS != '' |
| 244 | + run: | |
| 245 | + mkdir -p home/.sig && |
| 246 | + echo -n "$CODESIGN_P12" | tr % '\n' | base64 -d >home/.sig/codesign.p12 && |
| 247 | + echo -n "$CODESIGN_PASS" >home/.sig/codesign.pass && |
| 248 | + git config --global alias.signtool '!sh "/usr/src/build-extra/signtool.sh"' |
| 249 | + - name: Build ${{env.ARCHITECTURE}} ${{matrix.artifact.name}} |
| 250 | + run: | |
| 251 | + set -x |
| 252 | + eval /usr/src/build-extra/please.sh make_installers_from_mingw_w64_git --version=$(cat pkg-${{env.ARCHITECTURE}}/ver) -o artifacts --${{matrix.artifact.name}} --pkg=pkg-${{env.ARCHITECTURE}}/${{env.MINGW_PACKAGE_PREFIX}}-git-[0-9]*.tar.xz --pkg=pkg-${{env.ARCHITECTURE}}/${{env.MINGW_PACKAGE_PREFIX}}-git-doc-html-[0-9]*.tar.xz && |
| 253 | + if test portable = '${{matrix.artifact.name}}' && test -n "$(git config alias.signtool)" |
| 254 | + then |
| 255 | + git signtool artifacts/PortableGit-*.exe |
| 256 | + fi && |
| 257 | + openssl dgst -sha256 artifacts/${{matrix.artifact.fileprefix}}-*.${{matrix.artifact.fileextension}} | sed "s/.* //" >artifacts/sha-256.txt |
| 258 | + - name: Copy package-versions and pdbs |
| 259 | + if: matrix.artifact.name == 'installer' |
| 260 | + run: | |
| 261 | + cp /usr/src/build-extra/installer/package-versions.txt artifacts/ && |
| 262 | + a=$PWD/artifacts && |
| 263 | + p=$PWD/pkg-${{env.ARCHITECTURE}} && |
| 264 | + (cd /usr/src/build-extra && |
| 265 | + mkdir -p cached-source-packages && |
| 266 | + cp "$p"/*-pdb* cached-source-packages/ && |
| 267 | + GIT_CONFIG_PARAMETERS="'windows.sdk${{env.SDK_REPO_ARCH}}.path='" ./please.sh bundle_pdbs --arch=${{env.ARCHITECTURE}} --directory="$a" installer/package-versions.txt) |
| 268 | + - name: Publish ${{matrix.artifact.name}}-${{env.ARCHITECTURE}} |
| 269 | + uses: actions/upload-artifact@v3 |
| 270 | + with: |
| 271 | + name: ${{matrix.artifact.name}}-${{env.ARCHITECTURE}} |
| 272 | + path: artifacts |
0 commit comments