Skip to content

Adds info/changes for local action testing#46

Merged
MattKiazyk merged 10 commits intomainfrom
matt/localActionUpdates
Dec 9, 2020
Merged

Adds info/changes for local action testing#46
MattKiazyk merged 10 commits intomainfrom
matt/localActionUpdates

Conversation

@MattKiazyk
Copy link
Contributor

@MattKiazyk MattKiazyk commented Nov 27, 2020

Closes #45

Makes some changes so that we can test locally with ACT - https://github.com/nektos/act

Made a readme in actiontest/readme.md for more information.

Makes input values as secret so they can't be leaked to github console.

Copy link
Contributor

@interstateone interstateone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really glad that you figured out how to get act working, this will make the feedback cycle during development a lot shorter. I have a couple questions about these changes first but they're definitely a step in the right direction.

@@ -0,0 +1,11 @@
To run locally.

1. Install ACT - https://github.com/nektos/act
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also need Docker Desktop on macOS installed and running. I know this might seem obvious but I didn't have it running, and in this case act just fails with zero output which is a bit mystifying.

To run locally.

1. Install ACT - https://github.com/nektos/act
2. RUN: act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j testLocal --secret-file actiontest/.secrets --env-file actiontest/.env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. RUN: act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j testLocal --secret-file actiontest/.secrets --env-file actiontest/.env
2. RUN: act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j test --secret-file actiontest/.secrets --env-file actiontest/.env

I think this needs to change to be test to match the job name in test.yml, does that seem right or was this testLocal for another reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.. originally I had a separate workflow for testing locally (testLocal) this will become test

Couple of things:

- need to use the `ubuntu-latest=nektos/act-environments-ubuntu:18.04` docker image which is 18 GB!
- `test` - the name of your job from the test.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `test` - the name of your job from the test.yml
- `test` - the name of your job from the .github/workflows/test.yml file.

@@ -0,0 +1,28 @@
name: '1Password Secrets'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this file? I'm not sure I understand how it ends up being used if we do, because it's not directly referenced by the act command in the README. I'd prefer to use the one in the root in the repo instead of duplicating it, but I'm not sure if that's possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I could not get act to work properly using the regular action file and the regular test.yml

If you try to run the regular test.yml step that runs on github you'll get a

| Error: Cannot find module '/github/workspace/1password-action/dist/index.js'

Lots of people are having the same issue: nektos/act#391, nektos/act#185
Looks like an issue with the path when it copies. I tried a bunch of things, but one suggestion was to make a copy of your action.yml pointing it to '../dist/index.js' instead. This seemed to work.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encountered this same problem and got to this PR from a reference in nektos/act#185. This file is not needed (we were doing the same). What needs to happen is that the action needs to add the location path to the checkout. Since the test action is using ./ then checkout path would be: path: "1password-action"

- name: Test Action - local
if: ${{ env.ACT }}
uses: ./actiontest
id: secretsLocal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're assuming that only one of these Test Action steps ever runs, does this work if they both have the same step ID, and then we would only need the one verify step below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alas, you would think, but I was getting errors when I had the same id on multiple steps. This may work on github runner but didn't seem to work on docker.

.gitignore Outdated
lib/**/*

# For local action testing, these hold the secrets needed for testing.
actiontest/.secrets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

- uses: ./
- name: Test Action - local
if: ${{ env.ACT }}
uses: ./actiontest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would need to change to:

Suggested change
uses: ./actiontest
uses: ./

@@ -22,7 +22,23 @@ jobs:
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
path: "1password-action"

@MattKiazyk
Copy link
Contributor Author

@alfredodeza Thank you very much for the direction! 🙇 That simplifies things alot!

Copy link
Contributor

@interstateone interstateone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works really well, thanks Matt!

One last question about file organization in the repo but otherwise good to 🚢

package.json Outdated
"description": "TypeScript template action",
"main": "lib/main.js",
"scripts": {
"act": "act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j test --secret-file actiontest/.secrets --env-file actiontest/.environment",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to add this here

Comment on lines +3 to +5
1. Install Docker Desktop https://www.docker.com/products/docker-desktop
2. Install ACT - https://github.com/nektos/act
3. RUN: act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j test --secret-file actiontest/.secrets --env-file actiontest/.environment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Install Docker Desktop https://www.docker.com/products/docker-desktop
2. Install ACT - https://github.com/nektos/act
3. RUN: act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j test --secret-file actiontest/.secrets --env-file actiontest/.environment
1. Install Docker Desktop https://www.docker.com/products/docker-desktop
1. Install ACT - https://github.com/nektos/act
1. Copy .secrets-example to .secrets and replace `xxxx` with real values
1. Run `npm run act`

Adds the secrets step and prefer the act script. Also switched to let markdown rendering do the numbering correctly, which is a personal preference, because I find it makes it easier to edit later.

@@ -0,0 +1,12 @@
To run locally.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could remove this directory and have its contents in the root, and part of the reason for that is the root README.md has a Development heading, where these steps might be more easily discoverable. If we do this we'll also need to update the .gitignore with the new secrets path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@MattKiazyk MattKiazyk merged commit b6b1630 into main Dec 9, 2020
@MattKiazyk MattKiazyk deleted the matt/localActionUpdates branch December 9, 2020 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make sure all inputs are marked as secrets

3 participants