Example #1
0
        public async Task PushToMasterWithPipeline()
        {
            var stepFunctionsClient = new AmazonStepFunctionsClient();
            var assembly            = Assembly.GetExecutingAssembly();
            var accountId           = Environment.GetEnvironmentVariable("AWS_ACCOUNT_ID");
            var region = Environment.GetEnvironmentVariable("AWS_REGION");

            Octokit.Commit commit1, commit2, commit3;
            string         pipelineDefinition = null;

            #region Get the Pipeline Definition
            using (var stream = assembly.GetManifestResourceStream($"GithubWebhookEndToEnd.Resources.pipeline.asl.json"))
            {
                pipelineDefinition = await stream.ReadAsString();
            }
            #endregion

            #region Create Commit on Master

            commit1 = await github.Git.CreateCommit(
                repoOwner : repoOwner,
                repoName : repoName,
                before : null,
                branch : "master",
                message : "Create pipeline",
                files : new Dictionary <string, string>
            {
                [cicdFileName]     = "state-machine.template.yml",
                [pipelineFileName] = "pipeline.asl.json"
            },
                force : true
                );

            #endregion

            #region Assert State Machine was Created

            await cloudformation.WaitUntilStackHasStatus(stackName, "CREATE_COMPLETE");

            var stateMachineResponse = await stepFunctionsClient.DescribeStateMachineAsync(new DescribeStateMachineRequest
            {
                StateMachineArn = $"arn:aws:states:{region}:{accountId}:stateMachine:cfn-test-repo-cicd-pipeline",
            });

            Assert.That(stateMachineResponse.Definition, Is.EqualTo(pipelineDefinition));

            #endregion

            #region Create Another Commit

            commit2 = await github.Git.CreateCommit(
                repoOwner : repoOwner,
                repoName : repoName,
                before : commit1.Sha,
                branch : "master",
                message : "Add README",
                files : new Dictionary <string, string>
            {
                ["README.md"] = "README.md.1",
            },
                force : true
                );

            #endregion

            #region Assert Execution was Created
            {
                await Task.Delay(4000);

                var executionResponse = await stepFunctionsClient.ListExecutionsAsync(new ListExecutionsRequest
                {
                    StateMachineArn = $"arn:aws:states:{region}:{accountId}:stateMachine:cfn-test-repo-cicd-pipeline",
                });

                Assert.True(executionResponse.Executions.Any(execution => execution.Name == commit2.Sha));
            }
            #endregion

            #region Create Commit with [skip ci] in the message

            commit3 = await github.Git.CreateCommit(
                repoOwner : repoOwner,
                repoName : repoName,
                before : commit2.Sha,
                branch : "master",
                message : "Add README [skip ci]",
                files : new Dictionary <string, string>
            {
                ["README.md"] = "README.md.2",
            },
                force : true
                );

            #endregion

            #region Assert No Execution was Created
            {
                await Task.Delay(4000);

                var executionResponse = await stepFunctionsClient.ListExecutionsAsync(new ListExecutionsRequest
                {
                    StateMachineArn = $"arn:aws:states:{region}:{accountId}:stateMachine:cfn-test-repo-cicd-pipeline",
                });

                Assert.False(executionResponse.Executions.Any(execution => execution.Name == commit3.Sha));
            }
            #endregion
        }