Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guess update information based on GitHub Actions environment variables #1075

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9b7baee
Guess update information based on GitHub Actions environment variables
srevinsaju Sep 10, 2020
98079b9
style: use lower case (snake_case) for variable names
srevinsaju Sep 10, 2020
62be000
docs: Move travis CI specific documentation
srevinsaju Sep 10, 2020
fafcd41
fix: Check if github_repository and github_ref variables are not NULL
srevinsaju Sep 10, 2020
628d171
style: Fix github_actions if code suite indentation
srevinsaju Sep 10, 2020
c9b1a26
feat: Use snprintf instead of sprintf to avoid potential buffer overflow
srevinsaju Sep 10, 2020
4e7307a
fix: add an else block to inform the user of missing zsyncmake in git…
srevinsaju Sep 10, 2020
ee24c2b
Merge branch 'master' into github-actions
srevinsaju Sep 10, 2020
fe6f97b
fix: define a constant buffer_size = 1024 and reuse it in setting upd…
srevinsaju Nov 22, 2020
42b20c2
fix: use strcmp for empty string check
srevinsaju Nov 22, 2020
3e39d09
fix: explicitly check if return of strstr is NULL pointer
srevinsaju Nov 22, 2020
b0d2f01
style: follow C conventions of constant naming (Uppercase, move const…
srevinsaju Nov 22, 2020
5371a2a
fix: explicitly check if zsyncmake_path is not NULL
srevinsaju Nov 22, 2020
8550ec6
fix: remove an additional check for empty string.
srevinsaju Nov 22, 2020
0d4bac3
style: move update_information_buffer_size to a position prior to use…
srevinsaju Nov 22, 2020
27113a8
style: use updateinformation_buffer instead of an ambiguous variable …
srevinsaju Nov 22, 2020
6d00122
fix: free unused pointers once processing is complete using g_strfreev
srevinsaju Nov 22, 2020
3e3c3ad
Merge branch 'master' into github-actions
srevinsaju Apr 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/appimagetool.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ main (int argc, char *argv[])
char* github_token;
github_token = getenv("GITHUB_TOKEN");

/* Parse GitHub CI environment variables.
* https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
*/
char* github_repository = getenv("GITHUB_REPOSITORY");
char* github_ref = getenv("GITHUB_REF");

/* Parse GitLab CI environment variables.
* https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables
* echo "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw/QtQuickApp-x86_64.AppImage?job=${CI_JOB_NAME}"
Expand Down Expand Up @@ -869,11 +875,10 @@ main (int argc, char *argv[])
printf("%s\n", updateinformation);
}
}

/* If the user has not provided update information but we know this is a Travis CI build,
* then fill in update information based on TRAVIS_REPO_SLUG */
if(guess_update_information){
if(travis_repo_slug){
/* If the user has not provided update information but we know this is a Travis CI build,
* then fill in update information based on TRAVIS_REPO_SLUG */
if(!github_token) {
printf("Will not guess update information since $GITHUB_TOKEN is missing,\n");
if(0 != strcmp(travis_pull_request, "false")){
Expand Down Expand Up @@ -903,6 +908,33 @@ main (int argc, char *argv[])
printf("Will not guess update information since zsyncmake is missing\n");
}
}
} else if (github_repository != NULL && github_ref != NULL) {
printf("Running on GitHub Actions\n");
gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake");
if (zsyncmake_path) {
srevinsaju marked this conversation as resolved.
Show resolved Hide resolved
if (strstr(github_ref, "/pull/")) {
srevinsaju marked this conversation as resolved.
Show resolved Hide resolved
printf("Will not calculate update information for GitHub because this is a pull request\n");
} else {
printf("Guessing update information based on $GITHUB_REPOSITORY=%s and $GITHUB_REF=%s\n", github_repository, github_ref);
char buf[1024];
srevinsaju marked this conversation as resolved.
Show resolved Hide resolved
gchar **parts = g_strsplit (github_repository, "/", 2);
srevinsaju marked this conversation as resolved.
Show resolved Hide resolved
char* channel;
if (github_ref != "" && strstr(github_ref, "/continuous/")) {
srevinsaju marked this conversation as resolved.
Show resolved Hide resolved
channel = "latest";
srevinsaju marked this conversation as resolved.
Show resolved Hide resolved
} else {
channel = "continuous";
}
int is_zsync_write_success = snprintf(buf, 1024, "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync", parts[0], parts[1], channel, app_name_for_filename, arch);
srevinsaju marked this conversation as resolved.
Show resolved Hide resolved
if (is_zsync_write_success < 0) {
printf("Writing updateinformation failed. zsync information is too long. (> 1024)\n");
srevinsaju marked this conversation as resolved.
Show resolved Hide resolved
exit(is_zsync_write_success);
}
updateinformation = buf;
printf("%s\n", updateinformation);
}
} else {
printf("Will not guess update information since zsyncmake is missing\n");
}
} else if(CI_COMMIT_REF_NAME){
// ${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw/QtQuickApp-x86_64.AppImage?job=${CI_JOB_NAME}
gchar *zsyncmake_path = g_find_program_in_path ("zsyncmake");
Expand Down