Skip to content

Commit

Permalink
Merge pull request #117 from MatteoPologruto/move-to-gon-fork
Browse files Browse the repository at this point in the history
Bump release workflow to match the template in the tooling-project-assets repository
  • Loading branch information
umbynos authored Nov 29, 2023
2 parents 22a1f2b + 6f728dd commit 337855d
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 59 deletions.
120 changes: 90 additions & 30 deletions .github/workflows/release-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@ on:
jobs:
create-release-artifacts:
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
matrix:
os:
- Windows_32bit
- Windows_64bit
- Linux_32bit
- Linux_64bit
- macOS_64bit

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create changelog
# Avoid creating the same changelog for each os
if: matrix.os == 'Windows_32bit'
uses: arduino/create-changelog@v1
with:
tag-regex: '^[0-9]+\.[0-9]+\.[0-9]+.*$'
Expand All @@ -40,25 +53,39 @@ jobs:
version: 3.x

- name: Build
run: task dist:all
run: task dist:${{ matrix.os }}

- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.DIST_DIR }}

notarize-macos:
name: Notarize ${{ matrix.artifact.name }}
runs-on: macos-latest
needs: create-release-artifacts
outputs:
checksum-darwin_amd64: ${{ steps.re-package.outputs.checksum-darwin_amd64 }}
permissions:
contents: read

env:
GON_CONFIG_PATH: gon.config.hcl

strategy:
matrix:
artifact:
- name: darwin_amd64
path: "macOS_64bit.tar.gz"

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.DIST_DIR }}
Expand All @@ -67,7 +94,8 @@ jobs:
env:
KEYCHAIN: "sign.keychain"
INSTALLER_CERT_MAC_PATH: "/tmp/ArduinoCerts2020.p12"
KEYCHAIN_PASSWORD: keychainpassword # Arbitrary password for a keychain that exists only for the duration of the job, so not secret
# Arbitrary password for a keychain that exists only for the duration of the job, so not secret
KEYCHAIN_PASSWORD: keychainpassword
run: |
echo "${{ secrets.INSTALLER_CERT_MAC_P12 }}" | base64 --decode > "${{ env.INSTALLER_CERT_MAC_PATH }}"
security create-keychain -p "${{ env.KEYCHAIN_PASSWORD }}" "${{ env.KEYCHAIN }}"
Expand All @@ -88,37 +116,53 @@ jobs:
- name: Install gon for code signing and app notarization
run: |
wget -q https://github.com/mitchellh/gon/releases/download/v0.2.3/gon_macos.zip
wget -q https://github.com/Bearer/gon/releases/download/v0.0.27/gon_macos.zip
unzip gon_macos.zip -d /usr/local/bin
- name: Write gon config to file
# gon does not allow env variables in config file (https://github.com/mitchellh/gon/issues/20)
run: |
cat > "${{ env.GON_CONFIG_PATH }}" <<EOF
# See: https://github.com/Bearer/gon#configuration-file
source = ["${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"]
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"
sign {
application_identity = "Developer ID Application: ARDUINO SA (7KT7ZWMCJT)"
}
# Ask Gon for zip output to force notarization process to take place.
# The CI will ignore the zip output, using the signed binary only.
zip {
output_path = "unused.zip"
}
EOF
- name: Sign and notarize binary
env:
AC_USERNAME: ${{ secrets.AC_USERNAME }}
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
AC_PROVIDER: ${{ secrets.AC_PROVIDER }}
run: |
gon gon.config.hcl
gon "${{ env.GON_CONFIG_PATH }}"
- name: Re-package binary and update checksum
# This step performs the following:
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
# 2. Recalculate package checksum and replace it in the nnnnnn-checksums.txt file
- name: Re-package binary
id: re-package
working-directory: ${{ env.DIST_DIR }}
# Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
run: |
# GitHub's upload/download-artifact@v2 actions don't preserve file permissions,
# GitHub's upload/download-artifact actions don't preserve file permissions,
# so we need to add execution permission back until the action is made to do this.
chmod +x ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/${{ env.PROJECT_NAME }}
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"
TAG="${GITHUB_REF/refs\/tags\//}"
tar -czvf "${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz" \
-C ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/ ${{ env.PROJECT_NAME }} \
-C ../../ LICENSE.txt
CHECKSUM="$(shasum -a 256 ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz | cut -d " " -f 1)"
perl \
-pi \
-w \
-e "s/.*${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/${CHECKSUM} ${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz/g;" \
${{ env.DIST_DIR }}/*-checksums.txt
- name: Upload artifacts
uses: actions/upload-artifact@v2
PACKAGE_FILENAME="${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.artifact.path }}"
tar -czvf "$PACKAGE_FILENAME" \
-C "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/" "${{ env.PROJECT_NAME }}" \
-C ../../ LICENSE.txt
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: ${{ env.ARTIFACT_NAME }}
Expand All @@ -127,22 +171,38 @@ jobs:
create-release:
runs-on: ubuntu-latest
needs: notarize-macos
permissions:
contents: write

steps:
- name: Download artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.DIST_DIR }}

- name: Create checksum file
working-directory: ${{ env.DIST_DIR}}
run: |
TAG="${GITHUB_REF/refs\/tags\//}"
sha256sum ${{ env.PROJECT_NAME }}_${TAG}* > ${TAG}-checksums.txt
- name: Identify Prerelease
# This is a workaround while waiting for create-release action
# to implement auto pre-release based on tag
id: prerelease
run: |
wget -q -P /tmp https://github.com/fsaintjacques/semver-tool/archive/3.0.0.zip
unzip -p /tmp/3.0.0.zip semver-tool-3.0.0/src/semver >/tmp/semver && chmod +x /tmp/semver
if [[ "$(/tmp/semver get prerel "${GITHUB_REF/refs\/tags\//}")" ]]; then echo "::set-output name=IS_PRE::true"; fi
wget -q -P /tmp https://github.com/fsaintjacques/semver-tool/archive/3.2.0.zip
unzip -p /tmp/3.2.0.zip semver-tool-3.2.0/src/semver >/tmp/semver && chmod +x /tmp/semver
if [[ \
"$(
/tmp/semver get prerel \
"${GITHUB_REF/refs\/tags\//}"
)" != \
"" \
]]; then
echo "IS_PRE=true" >> $GITHUB_OUTPUT
fi
- name: Create Github Release and upload artifacts
uses: ncipollo/release-action@v1
Expand Down
15 changes: 0 additions & 15 deletions DistTasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,8 @@ version: "3"
vars:
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
GO_VERSION: "1.16.4"
CHECKSUM_FILE: "{{.VERSION}}-checksums.txt"

tasks:
all:
desc: Build for distribution for all platforms
cmds:
- task: Windows_32bit
- task: Windows_64bit
- task: Linux_32bit
- task: Linux_64bit
- task: macOS_64bit

Windows_32bit:
desc: Builds Windows 32 bit binaries
dir: "{{.TOOL_DIR}}/{{.DIST_DIR}}"
Expand All @@ -44,7 +34,6 @@ tasks:
-p "{{.BUILD_PLATFORM}}"
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../LICENSE.txt -j
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_386"
Expand All @@ -66,7 +55,6 @@ tasks:
-p "{{.BUILD_PLATFORM}}"
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../LICENSE.txt -j
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_amd64"
Expand All @@ -88,7 +76,6 @@ tasks:
-p "{{.BUILD_PLATFORM}}"
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd32"
Expand All @@ -110,7 +97,6 @@ tasks:
-p "{{.BUILD_PLATFORM}}"
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd64"
Expand All @@ -132,7 +118,6 @@ tasks:
-p "{{.BUILD_PLATFORM}}"
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_amd64"
Expand Down
14 changes: 0 additions & 14 deletions gon.config.hcl

This file was deleted.

0 comments on commit 337855d

Please sign in to comment.