Skip to content

Commit

Permalink
Add GitHub Actions workflow to automate releases (#40)
Browse files Browse the repository at this point in the history
* Added beginnings of package building code
* chore: create release CI job
* chore: add documentation section to changelog
* chore: make build-meshchat-package a reusable workflow
* chore: add build packages to release
* fix: update-version.sh can now be told version to set
* chore(ci): convert meshchat-api build to reusable workflow
* chore(ci): set release to only work on release branch

Signed-off-by: Gerard Hickey <hickey@kinetic-compute.com>
  • Loading branch information
hickey committed Feb 13, 2024
1 parent fabd985 commit 962b0c3
Show file tree
Hide file tree
Showing 9 changed files with 683 additions and 60 deletions.
33 changes: 23 additions & 10 deletions .github/workflows/build-meshchat-api-package.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
name: Build MeshChat API Package
on: push
env:
IPK_DIR: package/meshchat-api-ipkg
on:
workflow_call:
inputs:
build_version:
required: true
type: string
build_dir:
required: true
type: string

jobs:
create-meshchat-api-package:
runs-on: ubuntu-latest
# container:
# image: registry.gitlab.com/wt0f/gitlab-runner-images/shell:latest
steps:
- uses: actions/checkout@v3
- run: package/populate-meshchat-api-fs.sh $IPK_DIR
- run: package/update-version.sh $IPK_DIR
- run: package/ipk-build.sh $IPK_DIR
- uses: actions/upload-artifact@v3
- uses: actions/checkout@v4
- run: echo ${{ inputs.build_version }} > VERSION
- run: package/populate-meshchat-api-fs.sh ${{ inputs.build_dir }}
- run: package/update-version.sh ${{ inputs.build_dir }}
- run: package/ipk-build.sh ${{ inputs.build_dir }}
- id: detect-package-file
run: echo "file=$(ls -1 meshchat_*.ipk)" >> $GITHUB_OUTPUT
- run: echo "${{ steps.detect-package-file.outputs.file }}"
- uses: actions/upload-artifact@v4
with:
name: meshchat-api
path: meshchat-api_*
name: ${{ steps.detect-package-file.outputs.file }}
path: ${{ steps.detect-package-file.outputs.file }}
40 changes: 28 additions & 12 deletions .github/workflows/build-meshchat-package.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
name: Build MeshChat Package
on: push
env:
IPK_DIR: package/meshchat-ipkg
on:
workflow_call:
inputs:
build_version:
required: true
type: string
build_dir:
required: true
type: string

jobs:
create-meshchat-package:
runs-on: ubuntu-latest
# container:
# image: registry.gitlab.com/wt0f/gitlab-runner-images/shell:latest
outputs:
package_file: ${{ steps.detect-package-file.outputs.file }}
steps:
- uses: actions/checkout@v3
- run: package/populate-meshchat-fs.sh $IPK_DIR
- run: package/update-version.sh $IPK_DIR
- run: package/ipk-build.sh $IPK_DIR
- uses: actions/upload-artifact@v3
- uses: actions/checkout@v4
# - run: info "Populating the filesystem with MeshChat files"
- run: echo ${{ inputs.build_version }} > VERSION
- run: package/populate-meshchat-fs.sh ${{ inputs.build_dir }}
# - run: info "Updating version numbers to "
- run: package/update-version.sh ${{ inputs.build_dir }}
# - run: info "Packing up MeshChat files"
- run: package/ipk-build.sh ${{ inputs.build_dir }}
- id: detect-package-file
run: echo "file=$(ls -1 meshchat_*.ipk)" >> $GITHUB_OUTPUT
- run: echo "${{ steps.detect-package-file.outputs.file }}"
- uses: actions/upload-artifact@v4
with:
name: meshchat
path: |
meshchat_*.ipk
VERSION
name: ${{ steps.detect-package-file.outputs.file }}
path: ${{ steps.detect-package-file.outputs.file }}
72 changes: 72 additions & 0 deletions .github/workflows/release-meshchat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Release MeshChat Package
on:
pull_request:
types: [closed]
branches: [release]

jobs:
create-release:
runs-on: ubuntu-latest
# container:
# image: registry.gitlab.com/wt0f/gitlab-runner-images/node:latest
outputs:
build_version: ${{ steps.detect_version.outputs.build_version }}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_IT_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- run: npm install -g release-it @release-it/conventional-changelog @commitlint/config-conventional @commitlint/cli auto-changelog
- id: detect_version
run: echo "build_version=$(npx release-it --release-version)" >> $GITHUB_OUTPUT
- run: npx release-it -VV --ci
- run: git checkout master
- run: git rebase release
- run: git push

build-meshchat-package:
needs: create-release
uses:
./.github/workflows/build-meshchat-package.yaml
with:
build_version: ${{ needs.create-release.outputs.build_version }}
build_dir: package/meshchat-ipkg

build-meshchat-api-package:
needs: create-release
uses:
./.github/workflows/build-meshchat-api-package.yaml
with:
build_version: ${{ needs.create-release.outputs.build_version }}
build_dir: package/meshchat-ipkg

add-meshchat-package-to-release:
needs:
- build-meshchat-package
- build-meshchat-api-package
# container:
# image: registry.gitlab.com/wt0f/gitlab-runner-images/node:latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- run: git pull
- run: npm install -g release-it @release-it/conventional-changelog @commitlint/config-conventional @commitlint/cli auto-changelog
- uses: actions/download-artifact@v4
with:
name: ${{ needs.release_meshchat_package.outputs.package_file }}
path: ${{ needs.release_meshchat_package.outputs.package_file }}
- run: |
for file in *.ipk; do
echo "uploading $file"
npx release-it --ci --no-increment --no-git --no-npm --github.update=true --github.assets=$file
done
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_IT_TOKEN }}
6 changes: 3 additions & 3 deletions .release-it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ git:
tagName: "v${version}"
tagAnnotation: "Automated release: ${version}"
push: true
#requireBranch: release
requireBranch: release
requireCommits: true
changelog: "npx auto-changelog --stdout --commit-limit false"

github:
release: true
releaseName: "v${version}"
assets: ["*.ipk", "*.deb"]

npm:
publish: false
Expand All @@ -28,4 +27,5 @@ plugins:
section: Features
- type: fix
section: Bug Fixes

- tyep: docs
section: Documentation
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ released in v2.9.
If you are looking for a feature to be implemented or find a bug, please
be sure to [create an issue](https://github.com/hickey/meshchat/issues/new)
in the project so that it can be prioritized.


22 changes: 7 additions & 15 deletions meshchat
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ function send_message()
print("\r")

local message = query.message:gsub("\n", "\\n"):gsub('"', '\\"'):gsub("\t", " ")
local id = query.id or hash();

local epoch = os.time()
if query.epoch and tonumber(query.epoch) > epoch then
if tonumber(query.epoch) > epoch then
epoch = query.epoch
end

Expand All @@ -106,7 +106,7 @@ function send_message()
release_lock()
die("Cannot send message")
end
f:write(id .. "\t" .. epoch .. "\t" .. message .. "\t" .. query.call_sign .. "\t" .. node_name() .. "\t" .. platform .. "\t" .. query.channel .. "\n")
f:write(hash() .. "\t" .. epoch .. "\t" .. message .. "\t" .. query.call_sign .. "\t" .. node_name() .. "\t" .. platform .. "\t" .. query.channel .. "\n")
f:close()

sort_and_trim_db()
Expand All @@ -133,7 +133,6 @@ function messages()

local node = node_name()

-- read in message DB and parse the contents
local messages = {}
for line in io.lines(messages_db_file)
do
Expand All @@ -153,8 +152,6 @@ function messages()

if tonumber(query.epoch) and query.call_sign then
local users = {}

-- read the users status file
if nixio.fs.stat(local_users_status_file) then
for line in io.lines(local_users_status_file)
do
Expand All @@ -165,14 +162,11 @@ function messages()
end
end

-- set the timestamp
local epoch = os.time()
if tonumber(query.epoch) > epoch then
epoch = query.epoch
end

-- rewrite user status file updating the timestamp for requesting call sign
-- query.id is the meshchat_id
local f = io.open(local_users_status_file, "w")
if f then
local found_user = false
Expand All @@ -194,7 +188,6 @@ function messages()

release_lock()

-- order messages according to time
table.sort(messages, function(a, b) return a.epoch > b.epoch end)

output:write(luci.jsonc.stringify(messages))
Expand Down Expand Up @@ -359,7 +352,7 @@ function local_files_raw()
for file in nixio.fs.dir(local_files_dir)
do
local stat = nixio.fs.stat(local_files_dir .. "/" .. file)
f:write(file .. "\t" .. name .. "\t" .. stat.size .. "\t" .. stat.mtime .. "\t" .. platform .. "\n")
f:write(file .. "\t" .. name .. "\t" .. stat.size .. "\t" .. stat.mtime .. platform .. "\n")
end
f:close()

Expand Down Expand Up @@ -474,7 +467,7 @@ end
function messages_version_ui()
print("Content-type: application/json\r")
print("\r")

print(string.format([[{"messages_version":%s}]], get_messages_db_version()))

get_lock()
Expand All @@ -494,7 +487,6 @@ function messages_version_ui()
epoch = query.epoch
end

-- TODO refactor here and messages function into a single code block
local f = io.open(local_users_status_file, "w")
if f then
local found_user = false
Expand All @@ -519,7 +511,7 @@ end
function hosts()
print("Content-type: application/json\r")
print("\r")

local node = node_name()
local hosts = {}
for line in io.lines("/var/dhcp.leases")
Expand Down Expand Up @@ -570,7 +562,7 @@ end
function hosts_raw()
print("Content-type: application/json\r")
print("\r")

local hosts = {}
for line in io.lines("/var/dhcp.leases")
do
Expand Down

0 comments on commit 962b0c3

Please sign in to comment.