Skip to content

Commit

Permalink
Merge pull request #2 from alifeee/release
Browse files Browse the repository at this point in the history
Create automated release action
  • Loading branch information
alifeee authored Sep 21, 2023
2 parents f1ea021 + 2cd8c20 commit ee084ff
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 75 deletions.
178 changes: 178 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: Release

on:
release:
types:
- released

jobs:
verify_version_number:
runs-on: ubuntu-latest
steps:
- id: get_version
name: Get version
uses: jannemattila/get-version-from-tag@v1

- name: Verify version number
run: |
set -e
grep -F '"version": "${{ steps.get_version.outputs.version }}"' factorio/info.json
grep -F 'VERSION "${{ steps.get_version.outputs.version }}"' mumble/CMakeLists.txt
grep -F "<version>${{ steps.get_version.outputs.version }}</version>" mumble/manifest.xml
grep -F 'char *VERSION = "${{ steps.get_version.outputs.version }}";' mumble/plugin.c
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

steps:
- uses: actions/checkout@v3

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
echo "build-input-dir=${{ github.workspace }}/mumble" >> "$GITHUB_OUTPUT"
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ steps.strings.outputs.build-input-dir }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Upload a Build Artifact
uses: actions/[email protected]
with:
name: build
path: ${{ steps.strings.outputs.build-output-dir }}

bundle_mumble:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: build
path: build

- name: Bundle
run: |
mv build/libfactorio_linux_x86_64.so libplugin.so
mv build/Release/plugin.dll plugin.dll
mv mumble/manifest.xml manifest.xml
zip -MM factorio.mumble_plugin manifest.xml libplugin.so plugin.dll
- name: Upload a Build Artifact
uses: actions/[email protected]
with:
name: bundle
path: factorio.mumble_plugin

bundle_factorio:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- id: get_version
name: Get version
uses: jannemattila/get-version-from-tag@v1

- name: Bundle
run: |
cp -r factorio/ proximity-chat/
zip -r proximity-chat_${{ steps.get_version.outputs.version }}.zip proximity-chat
- name: Upload a Build Artifact
uses: actions/[email protected]
with:
name: proximity-chat_${{ steps.get_version.outputs.version }}.zip
path: proximity-chat_${{ steps.get_version.outputs.version }}.zip

add_release_files:
needs: [bundle_mumble, bundle_factorio]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- id: get_version
name: Get version
uses: jannemattila/get-version-from-tag@v1

- uses: actions/download-artifact@v3
with:
name: bundle
path: bundle

- uses: actions/download-artifact@v3
with:
name: proximity-chat_${{ steps.get_version.outputs.version }}.zip
path: proximity-chat_${{ steps.get_version.outputs.version }}.zip

- name: Get release
id: get_release
uses: bruceadams/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Upload mumble plugin
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: bundle/factorio.mumble_plugin
asset_name: factorio.mumble_plugin
asset_content_type: application/zip

- name: Upload factorio mod
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: proximity-chat_${{ steps.get_version.outputs.version }}.zip
asset_name: proximity-chat_${{ steps.get_version.outputs.version }}.zip
asset_content_type: application/zip
4 changes: 2 additions & 2 deletions factorio/info.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "mumble-positional-audio",
"version": "0.1.0",
"version": "0.2.0",
"title": "Mumble Positional Audio",
"author": "alifeee",
"factorio_version": "1.1",
"dependencies": ["base >= 1.1"],
"description": "This mod allows integration with the Mumble Factorio plugin, allowing proximity chat in multiplayer games."
}
}
2 changes: 1 addition & 1 deletion mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(TargetArch)

project(MumblePlugin
VERSION "0.1.0"
VERSION "0.2.0"
DESCRIPTION "Factorio Positional Audio Plugin"
LANGUAGES "C"
)
Expand Down
68 changes: 0 additions & 68 deletions mumble/logfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,71 +185,3 @@ void parse_factorio_logfile(float *x, float *y, float *z, int *player, int *surf
if (line)
free(line);
}

int main(int argc, char **argv)
{
char *homeDir = get_home_dir();
printf("Home dir: %s\n\n", homeDir);

if (is_factorio_logfile_there())
{
printf("Factorio logfile is present\n\n");
}
else
{
printf("Factorio logfile is not present. Terminating...\n");
return 0;
}

float x, y, z;
int player, surface;
char *server;
size_t server_len;

parse_factorio_logfile(&x, &y, &z, &player, &surface, &server, &server_len);

// log variables
printf("x: %f\n", x);
printf("y: %f\n", y);
printf("z: %f\n", z);
printf("player: %d\n", player);
printf("surface: %d\n", surface);
printf("server: %s\n", server);

// combine surface and server
char *context_str = malloc(server_len + 1 + 1 + 1);
strcpy(context_str, server);
strcat(context_str, "/");
char surface_str[12];
sprintf(surface_str, "%d", surface);
strcat(context_str, surface_str);
char *context = context_str;

printf("context: %s\n", context_str);

// get_file_modified_time
time_t modified_time = get_factorio_file_modified_time();
printf("modified time: %ld\n", modified_time);
// compare to time now
time_t now = time(NULL);
printf("now: %ld\n", now);
// difference
time_t diff = now - modified_time;
printf("diff: %ld\n", diff);
if (diff > 20)
{
printf("More than 20 seconds ago!\n");
}

// is recent?
if (is_factorio_logfile_recent(2))
{
printf("Factorio logfile is recent\n");
}
else
{
printf("Factorio logfile is not recent.\n");
}

return 0;
}
72 changes: 72 additions & 0 deletions mumble/logfile_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "logfile.c"

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
char *homeDir = get_home_dir();
printf("Home dir: %s\n\n", homeDir);

if (is_factorio_logfile_there())
{
printf("Factorio logfile is present\n\n");
}
else
{
printf("Factorio logfile is not present. Terminating...\n");
return 0;
}

float x, y, z;
int player, surface;
char *server;
size_t server_len;

parse_factorio_logfile(&x, &y, &z, &player, &surface, &server, &server_len);

// log variables
printf("x: %f\n", x);
printf("y: %f\n", y);
printf("z: %f\n", z);
printf("player: %d\n", player);
printf("surface: %d\n", surface);
printf("server: %s\n", server);

// combine surface and server
char *context_str = malloc(server_len + 1 + 1 + 1);
strcpy(context_str, server);
strcat(context_str, "/");
char surface_str[12];
sprintf(surface_str, "%d", surface);
strcat(context_str, surface_str);
char *context = context_str;

printf("context: %s\n", context_str);

// get_file_modified_time
time_t modified_time = get_factorio_file_modified_time();
printf("modified time: %ld\n", modified_time);
// compare to time now
time_t now = time(NULL);
printf("now: %ld\n", now);
// difference
time_t diff = now - modified_time;
printf("diff: %ld\n", diff);
if (diff > 20)
{
printf("More than 20 seconds ago!\n");
}

// is recent?
if (is_factorio_logfile_recent(2))
{
printf("Factorio logfile is recent\n");
}
else
{
printf("Factorio logfile is not recent.\n");
}

return 0;
}
2 changes: 1 addition & 1 deletion mumble/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<plugin os="linux" arch="x64">libplugin.so</plugin>
</assets>
<name>Factorio Positional Audio</name>
<version>0.1.0</version>
<version>0.2.0</version>
</bundle>
10 changes: 7 additions & 3 deletions mumble/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ void mumble_releaseResource(const void *pointer)

mumble_version_t mumble_getVersion()
{
char *VERSION = "0.2.0";

mumble_version_t version;
version.major = 0;
version.minor = 1;
version.patch = 0;
char *v = malloc(strlen(VERSION) + 1);
strcpy(v, VERSION); // cannot use strtok on const char*
version.major = atoi(strtok(v, "."));
version.minor = atoi(strtok(NULL, "."));
version.patch = atoi(strtok(NULL, "."));

return version;
}
Expand Down

0 comments on commit ee084ff

Please sign in to comment.