@@ -508,7 +508,7 @@ static GOptionEntry entries[] =
508
508
{
509
509
{ "list" , 'l' , 0 , G_OPTION_ARG_NONE , & list , "List files in SOURCE AppImage" , NULL },
510
510
{ "updateinformation" , 'u' , 0 , G_OPTION_ARG_STRING , & updateinformation , "Embed update information STRING; if zsyncmake is installed, generate zsync file" , NULL },
511
- { "guess" , 'g' , 0 , G_OPTION_ARG_NONE , & guess_update_information , "Guess update information based on Travis CI or GitLab environment variables" , NULL },
511
+ { "guess" , 'g' , 0 , G_OPTION_ARG_NONE , & guess_update_information , "Guess update information based on GitHub or GitLab environment variables" , NULL },
512
512
{ "version" , 0 , 0 , G_OPTION_ARG_NONE , & showVersionOnly , "Show version number" , NULL },
513
513
{ "verbose" , 'v' , 0 , G_OPTION_ARG_NONE , & verbose , "Produce verbose output" , NULL },
514
514
{ "sign" , 's' , 0 , G_OPTION_ARG_NONE , & sign , "Sign with gpg[2]" , NULL },
@@ -540,10 +540,34 @@ main (int argc, char *argv[])
540
540
travis_tag = getenv ("TRAVIS_TAG" );
541
541
char * travis_pull_request ;
542
542
travis_pull_request = getenv ("TRAVIS_PULL_REQUEST" );
543
+
544
+ /* Parse GitHub Actions environment variables.
545
+ * https://docs.github.com/en/actions/learn-github-actions/variables
546
+ * GITHUB_REPOSITORY: The owner and repository name. For example, octocat/Hello-World.
547
+ * GITHUB_REPOSITORY_OWNER: The repository owner's name. For example, octocat.
548
+ */
549
+
543
550
/* https://github.com/probonopd/uploadtool */
544
551
char * github_token ;
545
552
github_token = getenv ("GITHUB_TOKEN" );
546
553
554
+ // Construct the repository name from github_repository and github_repository_owner
555
+ // by removing the github_repository_owner from the beginning of github_repository
556
+ // and the slash that follows it
557
+ char * github_repository = getenv ("GITHUB_REPOSITORY" );
558
+ char * github_repository_owner = getenv ("GITHUB_REPOSITORY_OWNER" );
559
+ char * github_repository_name = NULL ;
560
+ if (github_repository_owner != NULL && github_repository != NULL ) {
561
+ char * owner_start = strstr (github_repository , github_repository_owner );
562
+ if (owner_start != NULL ) {
563
+ owner_start += strlen (github_repository_owner );
564
+ // Skip the '/'
565
+ if (* owner_start == '/' )
566
+ owner_start ++ ;
567
+ github_repository_name = owner_start ;
568
+ }
569
+ }
570
+
547
571
/* Parse GitLab CI environment variables.
548
572
* https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables
549
573
* echo "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_REF_NAME}/raw/QtQuickApp-x86_64.AppImage?job=${CI_JOB_NAME}"
@@ -913,10 +937,32 @@ main (int argc, char *argv[])
913
937
exit (1 );
914
938
}
915
939
916
- /* If the user has not provided update information but we know this is a Travis CI build,
917
- * then fill in update information based on TRAVIS_REPO_SLUG */
940
+ /* If the user has not provided update information but we know this is a CI build,
941
+ * then fill in update information based on well-known CI environment variables */
918
942
if (guess_update_information ){
919
- if (travis_repo_slug ){
943
+
944
+ if (github_repository_name ){
945
+ if (!github_token ) {
946
+ printf ("Will not guess update information since $GITHUB_TOKEN is missing\n" );
947
+ } else {
948
+ gchar * zsyncmake_path = g_find_program_in_path ("zsyncmake" );
949
+ if (zsyncmake_path ){
950
+ char buf [1024 ];
951
+ // gh-releases-zsync|probono|AppImages|latest|Subsurface-*x86_64.AppImage.zsync
952
+ int ret = snprintf (buf , "gh-releases-zsync|%s|%s|latest|%s*-%s.AppImage.zsync" , github_repository_owner , github_repository_name , app_name_for_filename , arch );
953
+ if (ret < 0 ) {
954
+ die ("snprintf error" );
955
+ } else if (ret >= sizeof (buf )) {
956
+ die ("snprintf buffer overflow" );
957
+ }
958
+ updateinformation = buf ;
959
+ printf ("Guessing update information based on $GITHUB_REPOSITORY=%s\n" , github_repository );
960
+ printf ("%s\n" , updateinformation );
961
+ } else {
962
+ printf ("Will not guess update information since zsyncmake is missing\n" );
963
+ }
964
+ }
965
+ } else if (travis_repo_slug ){
920
966
if (!github_token ) {
921
967
printf ("Will not guess update information since $GITHUB_TOKEN is missing,\n" );
922
968
if (0 != strcmp (travis_pull_request , "false" )){
@@ -938,7 +984,12 @@ main (int argc, char *argv[])
938
984
channel = "latest" ;
939
985
}
940
986
}
941
- sprintf (buf , "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync" , parts [0 ], parts [1 ], channel , app_name_for_filename , arch );
987
+ int ret = snprintf (buf , sizeof (buf ), "gh-releases-zsync|%s|%s|%s|%s*-%s.AppImage.zsync" , parts [0 ], parts [1 ], channel , app_name_for_filename , arch );
988
+ if (ret < 0 ) {
989
+ die ("snprintf error" );
990
+ } else if (ret >= sizeof (buf )) {
991
+ die ("snprintf buffer overflow" );
992
+ }
942
993
updateinformation = buf ;
943
994
printf ("Guessing update information based on $TRAVIS_TAG=%s and $TRAVIS_REPO_SLUG=%s\n" , travis_tag , travis_repo_slug );
944
995
printf ("%s\n" , updateinformation );
@@ -951,7 +1002,12 @@ main (int argc, char *argv[])
951
1002
gchar * zsyncmake_path = g_find_program_in_path ("zsyncmake" );
952
1003
if (zsyncmake_path ){
953
1004
char buf [1024 ];
954
- sprintf (buf , "zsync|%s/-/jobs/artifacts/%s/raw/%s-%s.AppImage.zsync?job=%s" , CI_PROJECT_URL , CI_COMMIT_REF_NAME , app_name_for_filename , arch , CI_JOB_NAME );
1005
+ int ret = snprintf (buf , sizeof (buf ), "zsync|%s/-/jobs/artifacts/%s/raw/%s-%s.AppImage.zsync?job=%s" , CI_PROJECT_URL , CI_COMMIT_REF_NAME , app_name_for_filename , arch , CI_JOB_NAME );
1006
+ if (ret < 0 ) {
1007
+ die ("snprintf error" );
1008
+ } else if (ret >= sizeof (buf )) {
1009
+ die ("snprintf buffer overflow" );
1010
+ }
955
1011
updateinformation = buf ;
956
1012
printf ("Guessing update information based on $CI_COMMIT_REF_NAME=%s and $CI_JOB_NAME=%s\n" , CI_COMMIT_REF_NAME , CI_JOB_NAME );
957
1013
printf ("%s\n" , updateinformation );
0 commit comments