@@ -5,7 +5,7 @@ import { info } from "@actions/core"
55import { warning } from "../io/io"
66import { isGitHubCI } from "../env/isCI"
77import { addEnv , cpprc_path , setupCppInProfile } from "../env/addEnv"
8- import { appendFileSync } from "fs"
8+ import { appendFileSync , existsSync } from "fs"
99import which from "which"
1010
1111let didUpdate : boolean = false
@@ -80,20 +80,35 @@ function initApt(apt: string) {
8080 "ca-certificates" ,
8181 "gnupg" ,
8282 ] )
83- try {
84- execSudo ( "apt-key" , [ "adv" , "--keyserver" , "keyserver.ubuntu.com" , "--recv-keys" , "3B4FE6ACC0B21F32" ] )
85- execSudo ( "apt-key" , [ "adv" , "--keyserver" , "keyserver.ubuntu.com" , "--recv-keys" , "40976EAF437D05B5" ] )
86- execSudo ( "apt-key" , [ "adv" , "--keyserver" , "keyserver.ubuntu.com" , "--recv-keys" , "1E9377A2BA9EF27F" ] )
87- } catch ( err ) {
88- warning ( `Failed to add keys: ${ err } ` )
89- }
83+ addAptKey ( [ "3B4FE6ACC0B21F32" , "40976EAF437D05B5" ] , "setup-cpp-ubuntu-archive.gpg" )
84+ addAptKey ( [ "1E9377A2BA9EF27F" ] , "setup-cpp-launchpad-toolchain.gpg" )
9085 if ( apt === "nala" ) {
9186 // enable utf8 otherwise it fails because of the usage of ASCII encoding
9287 addEnv ( "LANG" , "C.UTF-8" )
9388 addEnv ( "LC_ALL" , "C.UTF-8" )
9489 }
9590}
9691
92+ function addAptKey ( keys : string [ ] , name : string ) {
93+ try {
94+ if ( ! existsSync ( `/root/.gnupg/${ name } ` ) ) {
95+ for ( const key of keys ) {
96+ execSudo ( "gpg" , [
97+ "--no-default-keyring" ,
98+ "--keyring" ,
99+ name ,
100+ "--keyserver" ,
101+ "keyserver.ubuntu.com" ,
102+ "--recv-keys" ,
103+ key ,
104+ ] )
105+ }
106+ }
107+ } catch ( err ) {
108+ warning ( `Failed to add keys: ${ err } ` )
109+ }
110+ }
111+
97112export function updateAptAlternatives ( name : string , path : string ) {
98113 if ( isGitHubCI ( ) ) {
99114 return execSudo ( "update-alternatives" , [ "--install" , `/usr/bin/${ name } ` , name , path , "40" ] )
0 commit comments