-
-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test current code base as an integration test for PRs and pushes #505
Conversation
Codecov Report
@@ Coverage Diff @@
## dev-v4 #505 +/- ##
==========================================
Coverage ? 100.00%
==========================================
Files ? 6
Lines ? 179
Branches ? 50
==========================================
Hits ? 179
Misses ? 0
Partials ? 0 Continue to review full report at Codecov.
|
So, this failed in a good way. Things I like about this PR: It indicates that just installing the prod dependencies should do the trick for the action (3.7.1 ships dev dependencies, too). It runs an integration test. I'm tempted to stack |
I think adding the dry run stuff to this PR will be the only way this will work unfortunately, but I'm a big fan of this. It should really help! I'm thinking we should expand this to run the entire integration test suite and not just a single one. The release branch gets updated manually by me whenever I merge something into it (I just switch and run Thanks for this, it's really appreciated! |
.github/workflows/build.yml
Outdated
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should run v2
here with persist-credentials: false
as it's the latest version; https://github.com/JamesIves/github-pages-deploy-action/blob/dev/.github/workflows/integration.yml#L42-L45
.github/workflows/build.yml
Outdated
with: | ||
FOLDER: integration | ||
BASE_BRANCH: ${{ github.sha }} | ||
BRANCH: gh-pages-pr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider adding a cleanup step after this in the off chance that it does actually generate these branches (ie if someone with adequate permissions made a PR). This is a potential window for abuse so it's probably best we prevent things from lingering: https://github.com/JamesIves/github-pages-deploy-action/blob/dev/.github/workflows/integration.yml#L31-L35
I've spun dry-run into its own PR #526 , with some unit tests. With that, I wonder if I should move the steps into the |
Lemme gather my thoughts on this, I'll take a closer look later today! |
Quick question before I merge: Should this include the dry-run flag? I think keeping this in build/PR makes sense as the intention of this is to smoke test PR's instead of running the scheduled tests. |
I think this should, yes, otherwise the tests won't pass. Also, I still need to address your review comments, let me get to that real quick (I'm actually hacking on this right now 😄 ) |
Soooo, |
Yeah tackling it as part of this PR makes the most sense to me! |
Nice, I'm finding actual bugs now. Also bugs I introduced. |
For reference, |
I'm putting this into draft state for now, I need to do a couple of iterations here, probably. I'll update the PR here soon, but I'm also changing a lot, so feel free to comment and complain liberally. The high-level idea is that the mix of |
Sounds good to me, I'll keep an eye out. I've got a lot of spare time coming up this weekend so I'm hoping to knock out a lot of these remaining tasks for v4. |
For pull requests, the github.sha is the sha of the merge to the target branch, not the head of the PR. Special case that.
I also made the branches more generic, as there are now more of them.
Also add tests for dryRun and singleCommit and generateBranch code flows.
…ngleCommit This is a continuation of the no-checkout work, and sadly suggested pretty intensive changes.
I think this is in a shape where I'd appreciate feedback. Candid-european is perfectly fine. A few thoughts I have: I think the dry-run integration testing turned out rather well. I wish it was more strict, which might be be OK to do with checking the action output. Right now it's an environment, in particular with multiple deploy steps, that's interesting. Is there a reason to not make it an step output? I also entertained the idea to expose the count of commits done as step output, which could be checked for things like I introduced an abstraction of a git command. It's not placed anywhere logical, but just close to where it's used. I like being able to set options one by one, and then have the class generate the command string. I do think I only did this half-way, though. I also like the actual testing of Also, I'm a bit lost on how to test the error handling in |
I will take a look first thing tomorrow when I wake up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good, and I really appreciate you taking the time on this. I have a few comments/questions.
Regarding testing the error handling there's a way you can make the execute
function throw if it's given a specific string, I believe it's done here: https://github.com/JamesIves/github-pages-deploy-action/blob/dev/__tests__/git.test.ts#L56-L58
As we can't necessarily test git failures just ensuring that we have coverage on the catch would be significant, that way we know it will bubble up to the calling function and provide the user with an adequate error message.
__tests__/worktree.test.ts
Outdated
beforeAll(async () => { | ||
const silent = true | ||
tempdir = fs.mkdtempSync(path.join(os.tmpdir(), 'gh-deploy-')) | ||
const origin = path.join(tempdir, 'origin') | ||
await execute('git init origin', tempdir, silent) | ||
await execute('git config user.email "you@example.com"', origin, silent) | ||
await execute('git config user.name "Jane Doe"', origin, silent) | ||
await execute('git checkout -b main', origin, silent) | ||
fs.writeFileSync(path.join(origin, 'f1'), 'hello world\n') | ||
await execute('git add .', origin, silent) | ||
await execute('git commit -mc0', origin, silent) | ||
fs.writeFileSync(path.join(origin, 'f1'), 'hello world\nonce more\n') | ||
await execute('git add .', origin, silent) | ||
await execute('git commit -mc1', origin, silent) | ||
await execute('git checkout --orphan gh-pages', origin, silent) | ||
await execute('git reset --hard', origin, silent) | ||
await fs.promises.writeFile(path.join(origin, 'gh1'), 'pages content\n') | ||
await execute('git add .', origin, silent) | ||
await execute('git commit -mgh0', origin, silent) | ||
await fs.promises.writeFile( | ||
path.join(origin, 'gh1'), | ||
'pages content\ngoes on\n' | ||
) | ||
await execute('git add .', origin, silent) | ||
await execute('git commit -mgh1', origin, silent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain to me so I understand what's happening here. Is this setting up the requirements in the env for generateWorkTree
to run? It feels weird to manually run a sequence of git commands like this but I understand the need if it's just required setup.
If that is the case we should probably comment this file to indicate such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm adding a bunch of comments to the test file now.
__tests__/worktree.test.ts
Outdated
fs.writeFileSync(path.join(origin, 'f1'), 'hello world\n') | ||
await execute('git add .', origin, silent) | ||
await execute('git commit -mc0', origin, silent) | ||
fs.writeFileSync(path.join(origin, 'f1'), 'hello world\nonce more\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fs.writeFileSync(path.join(origin, 'f1'), 'hello world\nonce more\n') | |
fs.writeFileSync(path.join(origin, 'f1'), 'hello world\once more\n') |
This is a very unfortunate typo 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See, this happens when you're not a native speaker. Not really a typo, I'll just use \nand planets
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha yeah totally understand
src/git.ts
Outdated
constructor(branch: string) { | ||
this.branch = branch | ||
} | ||
toString(): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I love naming this toString
, but I get the idea of what's happening here. 😬
src/git.ts
Outdated
// Special case is singleCommit with existing history, when | ||
// we're really interested if the diff against the upstream branch | ||
// changed. | ||
const checkCmd = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be better named checkGitStatus
or something more descriptive.
) | ||
await execute(`git fetch`, action.workspace, action.silent) | ||
|
||
info(`Created the ${action.branch} branch… 🔧`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep the logging in place when a branch is created
src/git.ts
Outdated
@@ -33,34 +33,79 @@ export async function init(action: ActionInterface): Promise<void | Error> { | |||
} | |||
} | |||
|
|||
/* Generates the branch if it doesn't exist on the remote. */ | |||
export async function generateBranch(action: ActionInterface): Promise<void> { | |||
export class GitCheckout { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a good idea to throw this class and its methods into a worktree.ts
file as an associated worktree.test.ts
file already exists. That way each test file tests its adjacent functions/classes.
with: | ||
FOLDER: integration | ||
BRANCH: ${{ matrix.branch }} | ||
SINGLE_COMMIT: ${{ matrix.commit == 'singleCommit' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever!
I'm going to just add an explicit test file for error handing. The problem (AFAICT) is that you can only mock modules per test file. So I'm having one test file that doesn't mock |
Thanks for the review, I think I've got them all. I'm not all that fond of c3cddcb, but I also don't have a better idea. W/out that, coverage complains about the conditional check for changes files. I made that a separate commit so it's easier to mess with. |
Another idea I just had was to mock
in |
There is already a For the most part this is looking great! I'll merge this Sunday afternoon and get a pre-release up for this so we can start some more in-depth testing. |
I've been wondering about that a bit. Right now, I'm not too fond of using the same value for both test flags, but we could use an enum like
Than we only need one variable, but can combine different scenarios in one test. It's also explicit when setting up the test? |
I like the use of the enum! |
I have mixed feelings on whether a required or an optional The |
I see what you mean, it is somewhat confusing to have the two. I think for now let's merge this, and in a follow-up figure out if we can deprecate the use case of |
* Stop checking out workspace (#515) * Stop checking out base branch before deployment, drop option. * Don't check out default branch, as we don't check out base branch, drop option. * Don't stash/unstash as we don't update the workdir, drop preserve option. * Don't init the workspace * Only fetch the remote branch if it exists, only with depth 1. * Rely on previous checkouts to have handled lfs files correctly, drop option. * Update README, action.yml, integration tests * Set up eslint for test files. (#517) * Add DRY_RUN option, passing --dry-run to git push. (#526) See #499 for the proposal. * Simplifies Token Setup (#530) * Token simplification * Access Token / Github Token -> Token * Oops * Typos * Update README.md * Update README.md * Update action.yml Co-authored-by: Axel Hecht <axel@pike.org> * Update README.md Co-authored-by: Axel Hecht <axel@pike.org> * Update README.md Co-authored-by: Axel Hecht <axel@pike.org> * Adjust codeql action to latest recommendations (#540) Also, add the dev and release branches, and drop master. * Add workflow to update build and node_modules on release branches (#541) * Stores username/email in secrets * Removing stale bot integration * Test current code base as an integration test for PRs and pushes (#505) * Add a build step to create lib and node_modules artifact * Run integration test with built dist and current SHA as base For pull requests, the github.sha is the sha of the merge to the target branch, not the head of the PR. Special case that. * Use v2 checkout, and DRY_RUN for the integration test. I also made the branches more generic, as there are now more of them. * Fix #536, don't push at all on dryRun Also add tests for dryRun and singleCommit and generateBranch code flows. * Try to fix dryRun on new remote branches, refactor fetch * Try to fix dryRun, only fetch if origin branch exists * Refactor worktree setup to include branch generation and setup for singleCommit This is a continuation of the no-checkout work, and sadly suggested pretty intensive changes. * Set up git config to fix tests, also make debugging easier * Add matrix for existing and non-existing branch * Add matrix for singleCommit and not * Drop GITHUB_TOKEN, add DRY_RUN to action.yml * When deploying existing branch, add a modifcation and deploy again * Force branch checkout to work in redeployment scenarios * Make singleCommit easier to see in job descriptions * Review comments * Add a test-only property to action to test code paths with remote branch. * Introduce TestFlag enum to signal different test scenarios to unit tests * Fix util.test.ts * Update worktree.ts * Fix a few nits in tests and automation. Don't try to wordcount ls-rem… (#546) * Fix a few nits in tests and automation. Don't try to wordcount ls-remote. Nits in tests are around undoing changes made to the environment, and to not modify the checkout. * Describe suite with empty SHA * Lowercase Inputs (#547) * Lowercases inputs * Adjusts workflow tests and deployment_status * Use multi-line string for clean-exclude patterns. (#553) As this change is subtle, I'm taking the opportunity to change the underscore for the hyphen, which makes it less likely that users of this action will just pass in an old json array. * Hyphenate inputs and outputs, add step output, fix #558 (#559) * Hyphenate inputs and outputs, add step output, fix #558 I've also tried to make the clean docs a bit clearer, and consistent about clean being on my default. Still not totally happy with the intro of the docs there, though. * Add testing of step outputs to build integration tests * Security Docs * Integration tests * Revert "Integration tests" This reverts commit 639ff53. * Native SSH Key Support (#569) * SSH Key Support 🔑 * Update ssh.ts * Update src/ssh.ts Co-authored-by: Axel Hecht <axel@pike.org> * README fixes/etc * Unit Tests & README * ssh key * Update README.md * Update ssh.test.ts * Update ssh.test.ts * Update ssh.test.ts * Update ssh.test.ts * Update ssh.test.ts * Update ssh.test.ts * Update integration.yml Co-authored-by: Axel Hecht <axel@pike.org> * Deployment Issues (#583) * Update git.ts * Tests * Update git.ts * Formatting * Update src/git.ts Co-authored-by: Axel Hecht <axel@pike.org> * TestFlag * Logging * Update git.ts Co-authored-by: Axel Hecht <axel@pike.org> * Codespace Support (#584) * Add files via upload * Update README.md * Add files via upload * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * SSH Issues (#588) * Unsets Persisted Credentials (#587) * Persist * Config Setup/Tests * Assets * Update git.ts * Spacing * Update integration.yml * Update README.md Co-authored-by: Axel Hecht <axel@pike.org>
Description
Testing Instructions
Additional Notes