@@ -570,9 +570,10 @@ var mkdir = util_1.promisify(fs.mkdir);
570
570
var mkdtemp = util_1 . promisify ( fs . mkdtemp ) ;
571
571
// Environment Variables
572
572
/**
573
- * The URL of the repository to push to, one-of :
573
+ * The URL of the repository to push to, either :
574
574
*
575
575
* * an ssh URL to a repository
576
+ * * the string `"self"`
576
577
*/
577
578
var REPO = process . env . REPO ;
578
579
/**
@@ -598,7 +599,6 @@ var GITHUB_TOKEN = process.env.GITHUB_TOKEN;
598
599
// Implicit environment variables passed by GitHub
599
600
var GITHUB_REPOSITORY = process . env . GITHUB_REPOSITORY ;
600
601
var GITHUB_EVENT_PATH = process . env . GITHUB_EVENT_PATH ;
601
- var GITHUB_SHA = process . env . GITHUB_SHA ;
602
602
var GITHUB_ACTOR = process . env . GITHUB_ACTOR ;
603
603
// Error messages
604
604
var KNOWN_HOSTS_WARNING = "\n##[warning] KNOWN_HOSTS_FILE not set\nThis will probably mean that host verification will fail later on\n" ;
@@ -681,7 +681,7 @@ var writeToProcess = function (command, args, opts) { return new Promise(functio
681
681
} ) ;
682
682
} ) ; } ;
683
683
( function ( ) { return __awaiter ( void 0 , void 0 , void 0 , function ( ) {
684
- var TMP_PATH , REPO_TEMP , SSH_AUTH_SOCK , event , _a , _b , name , email , env , known_hosts , sshAgentMatch , _c , _d , branchCheck , folder , sha , push ;
684
+ var TMP_PATH , REPO_TEMP , SSH_AUTH_SOCK , event , _a , _b , name , email , sha , env , known_hosts , sshAgentMatch , _c , _d , branchCheck , folder , push ;
685
685
return __generator ( this , function ( _e ) {
686
686
switch ( _e . label ) {
687
687
case 0 : return [ 4 /*yield*/ , mkdtemp ( path . join ( os_1 . tmpdir ( ) , 'git-publish-subdir-action-' ) ) ] ;
@@ -705,31 +705,34 @@ var writeToProcess = function (command, args, opts) { return new Promise(functio
705
705
return [ 4 /*yield*/ , exec ( "git config --global user.email \"" + email + "\"" ) ] ;
706
706
case 4 :
707
707
_e . sent ( ) ;
708
+ return [ 4 /*yield*/ , exec ( "git rev-parse HEAD" ) ] ;
709
+ case 5 :
710
+ sha = ( _e . sent ( ) ) . stdout . trim ( ) . substr ( 0 , 7 ) ;
708
711
env = Object . assign ( { } , process . env , {
709
712
SSH_AUTH_SOCK : SSH_AUTH_SOCK
710
713
} ) ;
711
- if ( ! ( config . mode === 'ssh' ) ) return [ 3 /*break*/ , 11 ] ;
714
+ if ( ! ( config . mode === 'ssh' ) ) return [ 3 /*break*/ , 12 ] ;
712
715
known_hosts = config . knownHostsFile ;
713
716
// Use well-known known_hosts for certain domains
714
717
if ( ! known_hosts && config . parsedUrl . resource === 'github.com' ) {
715
718
known_hosts = KNOWN_HOSTS_GITHUB ;
716
719
}
717
- if ( ! ! known_hosts ) return [ 3 /*break*/ , 5 ] ;
720
+ if ( ! ! known_hosts ) return [ 3 /*break*/ , 6 ] ;
718
721
console . warn ( KNOWN_HOSTS_WARNING ) ;
719
- return [ 3 /*break*/ , 8 ] ;
720
- case 5 : return [ 4 /*yield*/ , mkdir ( SSH_FOLDER , { recursive : true } ) ] ;
721
- case 6 :
722
- _e . sent ( ) ;
723
- return [ 4 /*yield*/ , copyFile ( known_hosts , KNOWN_HOSTS_TARGET ) ] ;
722
+ return [ 3 /*break*/ , 9 ] ;
723
+ case 6 : return [ 4 /*yield*/ , mkdir ( SSH_FOLDER , { recursive : true } ) ] ;
724
724
case 7 :
725
725
_e . sent ( ) ;
726
- _e . label = 8 ;
726
+ return [ 4 /*yield*/ , copyFile ( known_hosts , KNOWN_HOSTS_TARGET ) ] ;
727
727
case 8 :
728
+ _e . sent ( ) ;
729
+ _e . label = 9 ;
730
+ case 9 :
728
731
// Setup ssh-agent with private key
729
732
console . log ( "Setting up ssh-agent on " + SSH_AUTH_SOCK ) ;
730
733
_d = ( _c = SSH_AGENT_PID_EXTRACT ) . exec ;
731
734
return [ 4 /*yield*/ , exec ( "ssh-agent -a " + SSH_AUTH_SOCK , { env : env } ) ] ;
732
- case 9 :
735
+ case 10 :
733
736
sshAgentMatch = _d . apply ( _c , [ ( _e . sent ( ) ) . stdout ] ) ;
734
737
if ( ! sshAgentMatch )
735
738
throw new Error ( 'Unexpected output from ssh-agent' ) ;
@@ -745,11 +748,11 @@ var writeToProcess = function (command, args, opts) { return new Promise(functio
745
748
}
746
749
throw err ;
747
750
} ) ] ;
748
- case 10 :
751
+ case 11 :
749
752
_e . sent ( ) ;
750
753
console . log ( "Private key added" ) ;
751
- _e . label = 11 ;
752
- case 11 :
754
+ _e . label = 12 ;
755
+ case 12 :
753
756
// Clone the target repo
754
757
return [ 4 /*yield*/ , exec ( "git clone \"" + config . repo + "\" \"" + REPO_TEMP + "\"" , {
755
758
env : env
@@ -765,7 +768,7 @@ var writeToProcess = function (command, args, opts) { return new Promise(functio
765
768
}
766
769
throw err ;
767
770
} ) ] ;
768
- case 12 :
771
+ case 13 :
769
772
// Clone the target repo
770
773
_e . sent ( ) ;
771
774
// Fetch branch if it exists
@@ -776,72 +779,71 @@ var writeToProcess = function (command, args, opts) { return new Promise(functio
776
779
console . error ( err ) ;
777
780
}
778
781
} ) ] ;
779
- case 13 :
782
+ case 14 :
780
783
// Fetch branch if it exists
781
784
_e . sent ( ) ;
782
785
// Check if branch already exists
783
786
console . log ( "##[info] Checking if branch " + config . branch + " exists already" ) ;
784
787
return [ 4 /*yield*/ , exec ( "git branch --list \"" + config . branch + "\"" , { env : env , cwd : REPO_TEMP } ) ] ;
785
- case 14 :
788
+ case 15 :
786
789
branchCheck = _e . sent ( ) ;
787
- if ( ! ( branchCheck . stdout . trim ( ) === '' ) ) return [ 3 /*break*/ , 21 ] ;
790
+ if ( ! ( branchCheck . stdout . trim ( ) === '' ) ) return [ 3 /*break*/ , 22 ] ;
788
791
// Branch does not exist yet, let's create an initial commit
789
792
console . log ( "##[info] " + config . branch + " does not exist, creating initial commit" ) ;
790
793
return [ 4 /*yield*/ , exec ( "git checkout --orphan \"" + config . branch + "\"" , { env : env , cwd : REPO_TEMP } ) ] ;
791
- case 15 :
792
- _e . sent ( ) ;
793
- return [ 4 /*yield*/ , exec ( "git rm -rf ." , { env : env , cwd : REPO_TEMP } ) . catch ( function ( err ) { } ) ] ;
794
794
case 16 :
795
795
_e . sent ( ) ;
796
- return [ 4 /*yield*/ , exec ( "touch README.md " , { env : env , cwd : REPO_TEMP } ) ] ;
796
+ return [ 4 /*yield*/ , exec ( "git rm -rf . " , { env : env , cwd : REPO_TEMP } ) . catch ( function ( err ) { } ) ] ;
797
797
case 17 :
798
798
_e . sent ( ) ;
799
- return [ 4 /*yield*/ , exec ( "git add README.md" , { env : env , cwd : REPO_TEMP } ) ] ;
799
+ return [ 4 /*yield*/ , exec ( "touch README.md" , { env : env , cwd : REPO_TEMP } ) ] ;
800
800
case 18 :
801
801
_e . sent ( ) ;
802
- return [ 4 /*yield*/ , exec ( "git commit -m \"Initial " + config . branch + " commit\" ", { env : env , cwd : REPO_TEMP } ) ] ;
802
+ return [ 4 /*yield*/ , exec ( "git add README.md " , { env : env , cwd : REPO_TEMP } ) ] ;
803
803
case 19 :
804
804
_e . sent ( ) ;
805
- return [ 4 /*yield*/ , exec ( "git push \"" + config . repo + "\" \"" + config . branch + "\"" , { env : env , cwd : REPO_TEMP } ) ] ;
805
+ return [ 4 /*yield*/ , exec ( "git commit -m \"Initial " + config . branch + " commit \"" , { env : env , cwd : REPO_TEMP } ) ] ;
806
806
case 20 :
807
807
_e . sent ( ) ;
808
- _e . label = 21 ;
808
+ return [ 4 /*yield*/ , exec ( "git push \"" + config . repo + "\" \"" + config . branch + "\"" , { env : env , cwd : REPO_TEMP } ) ] ;
809
809
case 21 :
810
+ _e . sent ( ) ;
811
+ _e . label = 22 ;
812
+ case 22 :
810
813
// Update contents of branch
811
814
console . log ( "##[info] Updating branch " + config . branch ) ;
812
815
return [ 4 /*yield*/ , exec ( "git checkout \"" + config . branch + "\"" , { env : env , cwd : REPO_TEMP } ) ] ;
813
- case 22 :
816
+ case 23 :
814
817
_e . sent ( ) ;
815
818
return [ 4 /*yield*/ , exec ( "git rm -rf ." , { env : env , cwd : REPO_TEMP } ) . catch ( function ( err ) { } ) ] ;
816
- case 23 :
819
+ case 24 :
817
820
_e . sent ( ) ;
818
821
folder = path . resolve ( process . cwd ( ) , config . folder ) ;
819
822
console . log ( "##[info] Copying all files from " + folder ) ;
820
823
// TODO: replace this copy with a node implementation
821
824
return [ 4 /*yield*/ , exec ( "cp -r " + folder + "/* ./" , { env : env , cwd : REPO_TEMP } ) ] ;
822
- case 24 :
825
+ case 25 :
823
826
// TODO: replace this copy with a node implementation
824
827
_e . sent ( ) ;
825
828
return [ 4 /*yield*/ , exec ( "git add -A ." , { env : env , cwd : REPO_TEMP } ) ] ;
826
- case 25 :
829
+ case 26 :
827
830
_e . sent ( ) ;
828
- sha = GITHUB_SHA ? GITHUB_SHA . substr ( 0 , 7 ) : 'unknown' ;
829
831
return [ 4 /*yield*/ , exec ( "git commit --allow-empty -m \"Update " + config . branch + " to output generated at " + sha + "\"" , { env : env , cwd : REPO_TEMP } ) ] ;
830
- case 26 :
832
+ case 27 :
831
833
_e . sent ( ) ;
832
834
console . log ( "##[info] Pushing" ) ;
833
835
return [ 4 /*yield*/ , exec ( "git push origin \"" + config . branch + "\"" , { env : env , cwd : REPO_TEMP } ) ] ;
834
- case 27 :
836
+ case 28 :
835
837
push = _e . sent ( ) ;
836
838
console . log ( push . stdout ) ;
837
839
console . log ( "##[info] Deployment Successful" ) ;
838
- if ( ! ( config . mode === 'ssh' ) ) return [ 3 /*break*/ , 29 ] ;
840
+ if ( ! ( config . mode === 'ssh' ) ) return [ 3 /*break*/ , 30 ] ;
839
841
console . log ( "##[info] Killing ssh-agent" ) ;
840
842
return [ 4 /*yield*/ , exec ( "ssh-agent -k" , { env : env } ) ] ;
841
- case 28 :
843
+ case 29 :
842
844
_e . sent ( ) ;
843
- _e . label = 29 ;
844
- case 29 : return [ 2 /*return*/ ] ;
845
+ _e . label = 30 ;
846
+ case 30 : return [ 2 /*return*/ ] ;
845
847
}
846
848
} ) ;
847
849
} ) ; } ) ( ) . catch ( function ( err ) {
0 commit comments