Skip to content

Commit

Permalink
use workflow to generate manifest and upload to s3
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomontero committed May 27, 2024
1 parent 8e4d3b1 commit 13eb075
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 105 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Build Openocd for all platforms
on: [workflow_call]

jobs:

build-mac-14-arm:
runs-on: macos-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install Dependencies
run: |
brew update
brew install automake
brew install texinfo
brew install libtool
export PATH=/usr/local/opt/texinfo/bin:$PATH
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for mac
uses: actions/upload-artifact@v4
with:
name: artifact-mac-14-arm-release
path: ./openocd
if-no-files-found: error

build-mac-12:
runs-on: macos-12
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install Dependencies
run: |
brew update
brew install automake
brew install texinfo
export PATH=/usr/local/opt/texinfo/bin:$PATH
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for mac
uses: actions/upload-artifact@v4
with:
name: artifact-mac-12-release
path: ./openocd
if-no-files-found: error

build-linux-22-04:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install libudev-dev
sudo apt-get install libtool
sudo apt-get install autoconf
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for linux
uses: actions/upload-artifact@v4
with:
name: artifact-linux-22-04-release
path: ./openocd
if-no-files-found: error

build-linux-20-04:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install libudev-dev
sudo apt-get install libtool
sudo apt-get install autoconf
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for linux
uses: actions/upload-artifact@v4
with:
name: artifact-linux-20-04-release
path: ./openocd
if-no-files-found: error

build-windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
install: git autotools mingw-w64-x86_64-cmake mingw-w64-ucrt-x86_64-gcc
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for windows
uses: actions/upload-artifact@v4
with:
name: artifact-windows-release
path: ./openocd
if-no-files-found: error
20 changes: 20 additions & 0 deletions .github/workflows/reusable-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish
on:
workflow_call:
inputs:
build_run_id:
description: 'The run id of the build job'
required: true
type: string

jobs:
download-artifacts:
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: dawidd6/[email protected]
with:
run_id: ${{ inputs.build_run_id }}
path: build/
- name: ls build
run: ls build
114 changes: 9 additions & 105 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,108 +8,12 @@ on:
workflow_dispatch:

jobs:

build-mac-14-arm:
runs-on: macos-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install Dependencies
run: |
brew update
brew install automake
brew install texinfo
brew install libtool
export PATH=/usr/local/opt/texinfo/bin:$PATH
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for mac
uses: actions/upload-artifact@v4
with:
name: artifact-mac-14-arm-release
path: ./openocd
if-no-files-found: error

build-mac-12:
runs-on: macos-12
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install Dependencies
run: |
brew update
brew install automake
brew install texinfo
export PATH=/usr/local/opt/texinfo/bin:$PATH
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for mac
uses: actions/upload-artifact@v4
with:
name: artifact-mac-12-release
path: ./openocd
if-no-files-found: error

build-linux-22-04:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install libudev-dev
sudo apt-get install libtool
sudo apt-get install autoconf
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for linux
uses: actions/upload-artifact@v4
with:
name: artifact-linux-22-04-release
path: ./openocd
if-no-files-found: error

build-linux-20-04:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install libudev-dev
sudo apt-get install libtool
sudo apt-get install autoconf
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for linux
uses: actions/upload-artifact@v4
with:
name: artifact-linux-20-04-release
path: ./openocd
if-no-files-found: error

build-windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
install: git autotools mingw-w64-x86_64-cmake mingw-w64-ucrt-x86_64-gcc
- name: build-openocd
run: |
./build-openocd.sh
- name: Publish OpenOCD packaged for windows
uses: actions/upload-artifact@v4
with:
name: artifact-windows-release
path: ./openocd
if-no-files-found: error
call-build:
uses: ./.github/workflows/reusable-build.yml
secrets: inherit
call-publish:
uses: ./.github/workflows/reusable-publish.yml
secrets: inherit
needs: call-build
with:
build_run_id: ${{ github.run_id }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ GTAGS
# A compile_commands.json can be generated using bear and will help tools such
# as clangd to locate header files and use correct $CFLAGS
compile_commands.json

build/
15 changes: 15 additions & 0 deletions compress-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Directory path
dir_path=${1:-"./build"}

# Iterate over each folder in the specified directory
for folder in "$dir_path"/openocd-*; do
if [[ -d $folder ]]; then
# Create the tar.gz archive
tar -czf "${folder}.tar.gz" -C "$dir_path" "$(basename "$folder")"
echo "Created archive: ${folder}.tar.gz"
else
echo "Skipping non-directory: $folder"
fi
done
64 changes: 64 additions & 0 deletions generate-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Read the version from the version file
version=$(cat version)
# Directory containing the files
dir_path=${1:-"./build"}

# Function to generate manifest.json content
generate_manifest() {
platform=$1
arch=$2
new_path=$3
name=$4
version=$5
sha256=$6

echo "platform: $platform"
cat <<EOL > ${dir_path}/${new_path}/${name}-${version}-manifest.json
{
"name": "${name}",
"version": "${version}",
"main": "./bin",
"url": "https://binaries.particle.io/openocd/${platform}/${arch}/${version}.tar.gz",
"sha256": "${sha256}"
}
EOL
}

# Iterate over each file and generate the manifest.json
for file in "$dir_path"/*.tar.gz; do
filename=$(basename -- "$file")
# Extract platform and arch from the filename
echo "doing something"
platform=$(echo $filename | awk -F '-' '{print $2}')
arch=$(echo $filename | awk -F '-' '{print $3}')

if [[ -z $platform || -z $arch ]]; then
echo "Unknown file pattern: $filename"
continue
fi

# Define name
name="openocd"

# Generate the new file name without the extension
new_file_name="${name}-${version}"
new_path="${name}-${platform}-${arch}"
# Create a directory for the current file to store the manifest.json
echo "creating directory ${dir_path}/${new_path}"
echo ${new_file_name}
echo ${new_path}
mkdir -p "${dir_path}/${new_path}"


# Copy the original file to the new directory
cp "$file" "${dir_path}/${new_path}/${new_file_name}.tar.gz"

# Calculate the SHA-256 checksum
sha256=$(sha256sum "$file" | awk '{ print $1 }')

# Generate the manifest.json for the current file
generate_manifest "$platform" "$arch" "$new_path" "$name" "$version" "$sha256"
echo "Generated ${dir_path}/${new_path}/${new_file_name}/${name}-${version}-manifest.json"
done
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.12.0-particle-d8e1d63

0 comments on commit 13eb075

Please sign in to comment.