|
| 1 | +name: 'Build release' |
| 2 | +author: 'Forgejo authors' |
| 3 | +description: | |
| 4 | + Build release |
| 5 | +
|
| 6 | +inputs: |
| 7 | + forgejo: |
| 8 | + description: 'URL of the Forgejo instance where the release is uploaded' |
| 9 | + required: true |
| 10 | + owner: |
| 11 | + description: 'User or organization where the release is uploaded, relative to the Forgejo instance' |
| 12 | + required: true |
| 13 | + repository: |
| 14 | + description: 'Repository where the release is uploaded, relative to the owner' |
| 15 | + required: true |
| 16 | + doer: |
| 17 | + description: 'Name of the user authoring the release' |
| 18 | + required: true |
| 19 | + tag-version: |
| 20 | + description: 'Version of the release derived from the tag withint the leading v' |
| 21 | + required: true |
| 22 | + suffix: |
| 23 | + description: 'Suffix to add to the image tag' |
| 24 | + token: |
| 25 | + description: 'token' |
| 26 | + required: true |
| 27 | + dockerfile: |
| 28 | + description: 'path to the dockerfile' |
| 29 | + default: 'Dockerfile' |
| 30 | + platforms: |
| 31 | + description: 'Coma separated list of platforms' |
| 32 | + default: 'linux/amd64,linux/arm64' |
| 33 | + release-notes: |
| 34 | + description: 'Full text of the release notes' |
| 35 | + default: 'Release notes placeholder' |
| 36 | + binary-name: |
| 37 | + description: 'Name of the binary' |
| 38 | + binary-path: |
| 39 | + description: 'Path of the binary within the container to extract into binary-name' |
| 40 | + verbose: |
| 41 | + description: 'Increase the verbosity level' |
| 42 | + default: 'false' |
| 43 | + |
| 44 | +runs: |
| 45 | + using: "composite" |
| 46 | + steps: |
| 47 | + - run: echo "${{ github.action_path }}" >> $GITHUB_PATH |
| 48 | + shell: bash |
| 49 | + |
| 50 | + - name: Install dependencies |
| 51 | + run: | |
| 52 | + apt-get install -y -qq xz-utils |
| 53 | +
|
| 54 | + - name: set -x if verbose is required |
| 55 | + id: verbose |
| 56 | + run: | |
| 57 | + if ${{ inputs.verbose }} ; then |
| 58 | + echo "shell=set -x" >> "$GITHUB_OUTPUT" |
| 59 | + fi |
| 60 | +
|
| 61 | + - name: Create the insecure and buildx-config variables for the container registry |
| 62 | + id: registry |
| 63 | + run: | |
| 64 | + ${{ steps.verbose.outputs.shell }} |
| 65 | + url="${{ inputs.forgejo }}" |
| 66 | + hostport=${url##http*://} |
| 67 | + hostport=${hostport%%/} |
| 68 | + echo "host-port=${hostport}" >> "$GITHUB_OUTPUT" |
| 69 | + if ! [[ $url =~ ^http:// ]] ; then |
| 70 | + exit 0 |
| 71 | + fi |
| 72 | + cat >> "$GITHUB_OUTPUT" <<EOF |
| 73 | + insecure=true |
| 74 | + buildx-config<<ENDVAR |
| 75 | + [registry."${hostport}"] |
| 76 | + http = true |
| 77 | + ENDVAR |
| 78 | + EOF |
| 79 | +
|
| 80 | + - name: Allow docker pull/push to forgejo |
| 81 | + if: ${{ steps.registry.outputs.insecure }} |
| 82 | + run: |- |
| 83 | + mkdir -p /etc/docker |
| 84 | + cat > /etc/docker/daemon.json <<EOF |
| 85 | + { |
| 86 | + "insecure-registries" : ["${{ steps.registry.outputs.host-port }}"], |
| 87 | + "bip": "172.26.0.1/16" |
| 88 | + } |
| 89 | + EOF |
| 90 | +
|
| 91 | + - name: Install docker |
| 92 | + run: | |
| 93 | + echo deb http://deb.debian.org/debian bullseye-backports main | tee /etc/apt/sources.list.d/backports.list && apt-get -qq update |
| 94 | + DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -qq -y -t bullseye-backports docker.io |
| 95 | +
|
| 96 | + - uses: https://github.com/docker/setup-buildx-action@v2 |
| 97 | + with: |
| 98 | + config-inline: | |
| 99 | + ${{ steps.registry.outputs.buildx-config }} |
| 100 | +
|
| 101 | + - name: Login to the container registry |
| 102 | + run: | |
| 103 | + BASE64_AUTH=`echo -n "${{ inputs.doer }}:${{ inputs.token }}" | base64 -w0` |
| 104 | + mkdir -p ~/.docker |
| 105 | + echo "{\"auths\": {\"$CI_REGISTRY\": {\"auth\": \"$BASE64_AUTH\"}}}" > ~/.docker/config.json |
| 106 | + env: |
| 107 | + CI_REGISTRY: "${{ steps.registry.outputs.host-port }}" |
| 108 | + |
| 109 | + - name: Build the container image for each architecture |
| 110 | + uses: https://github.com/docker/build-push-action@v4 |
| 111 | + # workaround until https://github.com/docker/build-push-action/commit/d8823bfaed2a82c6f5d4799a2f8e86173c461aba is in @v4 or @v5 is released |
| 112 | + env: |
| 113 | + ACTIONS_RUNTIME_TOKEN: '' |
| 114 | + with: |
| 115 | + context: . |
| 116 | + push: true |
| 117 | + file: ${{ inputs.dockerfile }} |
| 118 | + platforms: ${{ inputs.platforms }} |
| 119 | + tags: ${{ steps.registry.outputs.host-port }}/${{ inputs.owner }}/${{ inputs.repository }}:${{ inputs.tag-version }}${{ inputs.suffix }} |
| 120 | + |
| 121 | + - name: Extract the binary from the container images into the release directory |
| 122 | + if: inputs.binary-name != '' |
| 123 | + run: | |
| 124 | + ${{ steps.verbose.outputs.shell }} |
| 125 | + mkdir -p release |
| 126 | + cd release |
| 127 | + for platform in $(echo ${{ inputs.platforms }} | tr ',' ' '); do |
| 128 | + arch=$(echo $platform | sed -e 's|linux/||g' -e 's|arm/v6|arm-6|g') |
| 129 | + docker create --platform $platform --name forgejo-$arch ${{ steps.registry.outputs.host-port }}/${{ inputs.owner }}/${{ inputs.repository }}:${{ inputs.tag-version }}${{ inputs.suffix }} |
| 130 | + binary="${{ inputs.binary-name }}-${{ inputs.tag-version }}-linux" |
| 131 | + docker cp forgejo-$arch:${{ inputs.binary-path }} $binary-$arch |
| 132 | + chmod +x $binary-$arch |
| 133 | + # the displayed version is converted with - sometime changed into +, deal with it |
| 134 | + pattern=$(echo "${{ inputs.tag-version }}" | tr - .) |
| 135 | + if ! ./$binary-$arch --version | grep "$pattern" ; then |
| 136 | + echo "ERROR: expected version pattern $pattern not found in the output of $binary-$arch --version" |
| 137 | + ./$binary-$arch --version |
| 138 | + exit 1 |
| 139 | + fi |
| 140 | + xz --keep -9 $binary-$arch |
| 141 | + shasum -a 256 $binary-$arch > $binary-$arch.sha256 |
| 142 | + shasum -a 256 $binary-$arch.xz > $binary-$arch.xz.sha256 |
| 143 | + docker rm forgejo-$arch |
| 144 | + done |
| 145 | +
|
| 146 | + - name: publish release |
| 147 | + if: inputs.binary-name != '' |
| 148 | + uses: https://code.forgejo.org/actions/forgejo-release@v1 |
| 149 | + with: |
| 150 | + direction: upload |
| 151 | + release-dir: release |
| 152 | + release-notes: "${{ inputs.release-notes }}" |
| 153 | + token: ${{ inputs.token }} |
| 154 | + verbose: ${{ steps.verbose.outputs.value }} |
0 commit comments