@@ -47,8 +47,18 @@ interface TailscaleConfig {
4747 pingHosts : string [ ] ;
4848}
4949
50+ type tailnetInfo = {
51+ MagicDNSSuffix : string ;
52+ MagicDNSEnabled : boolean ;
53+ } ;
54+
55+ type tailscaleStatus = {
56+ BackendState : string ;
57+ CurrentTailnet : tailnetInfo ;
58+ } ;
59+
5060// Cross-platform Tailscale local API status check
51- async function getTailscaleStatus ( ) : Promise < any > {
61+ async function getTailscaleStatus ( ) : Promise < tailscaleStatus > {
5262 const platform = os . platform ( ) ;
5363
5464 if ( platform === platformWin32 ) {
@@ -171,6 +181,9 @@ async function run(): Promise<void> {
171181 core . debug ( `Tailscale status: ${ JSON . stringify ( status ) } ` ) ;
172182 if ( status . BackendState === "Running" ) {
173183 core . info ( "✅ Tailscale is running and connected!" ) ;
184+ if ( runnerOS === runnerMacOS ) {
185+ await configureDNSOnMacOS ( status ) ;
186+ }
174187 await pingHostsIfNecessary ( config ) ;
175188 // Explicitly exit to prevent hanging
176189 process . exit ( 0 ) ;
@@ -180,6 +193,12 @@ async function run(): Promise<void> {
180193 }
181194 } catch ( err ) {
182195 core . warning ( `Failed to get Tailscale status: ${ err } ` ) ;
196+ if ( runnerOS === runnerMacOS ) {
197+ core . setFailed (
198+ `❌ Tailscale status is required in order to configure macOS`
199+ ) ;
200+ process . exit ( 2 ) ;
201+ }
183202 // Still exit successfully since the main connection worked
184203 core . info ( "✅ Tailscale daemon is connected!" ) ;
185204 await pingHostsIfNecessary ( config ) ;
@@ -799,4 +818,29 @@ async function installCachedBinaries(
799818 }
800819}
801820
821+ async function configureDNSOnMacOS ( status : tailscaleStatus ) : Promise < void > {
822+ if ( ! status . CurrentTailnet . MagicDNSEnabled ) {
823+ core . info ( "MagicDNS is disabled, not configuring DNS" ) ;
824+ return ;
825+ }
826+
827+ core . info (
828+ `Setting system DNS server to 100.100.100.100 and searchdomains to ${ status . CurrentTailnet . MagicDNSSuffix } `
829+ ) ;
830+ try {
831+ await exec . exec ( "networksetup" , [
832+ "-setdnsservers" ,
833+ "Ethernet" ,
834+ "100.100.100.100" ,
835+ ] ) ;
836+ await exec . exec ( "networksetup" , [
837+ "-setsearchdomains" ,
838+ "Ethernet" ,
839+ status . CurrentTailnet . MagicDNSSuffix ,
840+ ] ) ;
841+ } catch ( e ) {
842+ throw Error ( `Failed to configure DNS on macOS: ${ e } ` ) ;
843+ }
844+ }
845+
802846run ( ) ;
0 commit comments