Skip to content

Commit

Permalink
Merge pull request #263 from thierrymarianne/complete-github-actions-…
Browse files Browse the repository at this point in the history
…workflow-for-windows

Add scripts to build zip archive containing binaries for windows
  • Loading branch information
cjdelisle committed Jun 29, 2021
2 parents a2932c2 + a8e3f8d commit 350a3bf
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 51 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,42 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: ${{ env.RELEASE_NAME }}

windows:
needs: release

runs-on: ubuntu-latest

steps:

- name: Set env
run: echo "RELEASE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Install packages
run: sudo apt-get install rpm jq bash curl zip

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x

- run: go version

- uses: actions/checkout@v2

- name: Build binaries
run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/build-windows-package.sh"
env:
PKT_FAIL_DIRTY: 1
RELEASE_NAME: ${{ env.RELEASE_NAME }}

- uses: actions/upload-artifact@main
with:
path: |
${{ github.workspace }}/${{ env.RELEASE_NAME }}-win.zip
- name: Publish release
run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/release-windows-package.sh"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: ${{ env.RELEASE_NAME }}
47 changes: 0 additions & 47 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions contrib/github-actions/build-windows-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

function build() {
cd "${GITHUB_WORKSPACE}" || exit

source ./do GOOS=windows GOARCH=amd64

mkdir ./bin/bin

mv ./bin/*.exe ./bin/bin

cd bin || exit

zip -r "./${RELEASE_NAME}-win.zip" ./bin

mv -v "./${RELEASE_NAME}-win.zip" "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-win.zip'
}
build
4 changes: 2 additions & 2 deletions contrib/github-actions/release-linux-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ function publish() {
--data-binary @${binary} \
-H 'Content-Type: application/octet-stream' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${upload_url}?name=${release_name}${extension}"
"${upload_url}?name=${release_name}-linux${extension}"

curl \
-X POST \
--data "$checksum" \
-H 'Content-Type: text/plain' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${upload_url}?name=${release_name}${extension}.sha256sum"
"${upload_url}?name=${release_name}-linux${extension}.sha256sum"
}

publish "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-linux-x86_64.rpm' '.rpm'
Expand Down
4 changes: 2 additions & 2 deletions contrib/github-actions/release-macos-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ function publish() {
--data-binary @${binary} \
-H 'Content-Type: application/octet-stream' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${upload_url}?name=${release_name}${extension}"
"${upload_url}?name=${release_name}-macos${extension}"

curl \
-X POST \
--data "$checksum" \
-H 'Content-Type: text/plain' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${upload_url}?name=${release_name}${extension}.sha256sum"
"${upload_url}?name=${release_name}-macos${extension}.sha256sum"
}

publish "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-mac.pkg' '.pkg'
55 changes: 55 additions & 0 deletions contrib/github-actions/release-windows-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

function publish() {
local archive
archive="${1}"

local extension
extension="${2}"

if [ ! -e "${archive}" ];
then
echo 'Invalid archive ('"${archive}"')'
return 1
fi

local checksum
checksum="$(sha256sum "${archive}" | cut -d ' ' -f 1)"

local base_url
base_url='https://api.github.com/repos/'"${GITHUB_REPOSITORY}"

local upload_url
upload_url="$(curl \
-H 'Content-Type: application/octet-stream' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${base_url}"/releases 2>> /dev/null | \
jq -r '.[] | .upload_url' | \
head -n1)"

upload_url=${upload_url/\{?name,label\}/}

local release_name
release_name="$(curl \
-H 'Content-Type: application/octet-stream' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${base_url}"/releases 2>> /dev/null | \
jq -r '.[] | .tag_name' | \
head -n1)"

curl \
-X POST \
--data-binary @${archive} \
-H 'Content-Type: application/octet-stream' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${upload_url}?name=${release_name}-windows${extension}"

curl \
-X POST \
--data "$checksum" \
-H 'Content-Type: text/plain' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${upload_url}?name=${release_name}-windows${extension}.sha256sum"
}

publish "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-win.zip' '.zip'

0 comments on commit 350a3bf

Please sign in to comment.