Skip to content

Commit

Permalink
chore: update to dynamically generate json file (microsoft#3041)
Browse files Browse the repository at this point in the history
* update to improve speed of filing PR

* Revert "update to improve speed of filing PR"

This reverts commit 83c177e.

* remove and ignore local event branch file

* add bash script to dynamically create local git branch file

* update documentation
  • Loading branch information
awentzel authored May 5, 2020
1 parent f8a7ace commit 605a9a3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,39 @@ Required to run GitHub Actions on VMs. Choose your preferred Docker setup https:
Required to run GitHub Actions locally.

```bash
$ brew install nektos/tap/act
brew install nektos/tap/act
```

### 3. Install Azure CLI
Required to integrate GitHub Actions and Azure.

```bash
$ azure login
azure login
```

## Configure
The `.actrc` file contains the default configuration and run methods. The `./.github/workflows/testing/push.json` file contains the default GitHub events to run.
1. The `.actrc` file contains the default configuration and run methods.
2. Run this Bash script `ci-act-event.sh` to dynamically generate the required configuration file for Act. Two questions will be asked to collect the local git branch name and GitHub event. An example might look like `.github/workflows/testing/push.json` where "push" is the github.event to trigger a GitHub Action against the branch named inside that same file. This file is `.gitignored` so it will need regenerated for testing.

Update the "ref" values in `./.github/workflows/testing/push.json` to point to the local git branch to test. Then perform the following to execute against that branch when running `act`.
```bash
cd .github/workflows/testing
bash ci-act-event.sh
```

A new file `{some-name}.json` will be generated inside `/testing/`. This is the local git branch that `Act` will run.

Run the event from the `/testing/*` folder as indicated with `-W` or `--workflows` arguments.

```bash
$ act -e `./.github/workflows/testing/push.json` -W "./.github/workflows/testing/"
$ act -e `.github/workflows/testing/${github_event}.json` -W "./.github/workflows/testing/"
```

## Test
`./.github/workflows/testing/ci-daily-local.yml` is used to test locally CI settings.

```bash
$ act -j build_local_linux -e "./.github/workflows/testing/push.json" -W "./.github/workflows/testing/"
$ act -j build_local_linux -e "./.github/workflows/testing/${github_event}.json" -W "./.github/workflows/testing/"
```

## Cleanup
When installing packages on docker instances, if versions change, it's important to kill the docker instance and rebuild.

Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/testing/ci-act-event.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

echo " ------------------------------------------------------------------------------------------------ "
echo "| This script will dynamically create an event.json file for use by Nektos/Act in testing GitHub |"
echo "| Actions locally. |"
echo " -------------------------------------------------------------------------------------------------"

# Ask for Branch Name
echo -n "Enter git branch name? "
read branch_name

# Ask for Event Type
echo -n "Enter the GitHub Event to trigger the GitHub Action? "
read github_event

# Combine user inputs into the json template
# Set contents of the file to be overwritten
echo '{
"push": {
"head": {
"ref": "'$branch_name'"
},
"base": {
"ref": "'$branch_name'"
}
}
}' >& $github_event.json

10 changes: 0 additions & 10 deletions .github/workflows/testing/push.json

This file was deleted.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ sites/website/i18n/
docs/en/packages/*/README.md

# TypeDoc generated subsites
docs/en/packages/*/api/
docs/en/packages/*/api/

# GitHub Actions Local Testing
.github/workflows/testing/*.json

0 comments on commit 605a9a3

Please sign in to comment.