Deploying to production after git push #22123
-
I’m currently trying to optimize my workflow but I’m a bit lost on how to cut down deployment time once I push to production. At the moment my workflow is something like:
While it’s not prone to many errors, it’s definitely an annoyance to do over and over since the process is always the same. I’m wondering if there’s any way to automatically pull changes and build my application once I push changes to my Github repository and the tests successfully pass? I’m aware of Jenkins, but it seems like it would add a lot of overhead that I don’t really need since most of my repositories are simple websites. Is there a way to do this without external tools? Ideally I’m looking to implement something that would:
Note: I’ve found a lot of tutorials that involve creating a bare repo on the server and then manually pushing code to that. This wouldn’t be a great solution as I would essentially need to push to two different repositories every time. But if there’s any way to implement this with Github being the middle man that would be fantastic! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
This is something you could do with Github Actions. Depending on how much access you want to give Actions to your production system I see two concepts you might use:
Personally I’d lean more towards the first because there’s less risk of production server credentials leaking. As an extra precaution you could sign commits (or tags) and verify them on your production server before building. 🙂 |
Beta Was this translation helpful? Give feedback.
-
airtower-luna:
How would this work exactly? Is there a way to hide auth tokens within Github Actions?
airtower-luna:
Same question for this. |
Beta Was this translation helpful? Give feedback.
-
creativiii:
Yes, it’s called Secrets. Take a look at the documentation: Creating and storing encrypted secrets |
Beta Was this translation helpful? Give feedback.
-
airtower-luna:
Oh that’s great! No idea that was a thing. So I can use something like this to make a request to a PHP file that runs shell_exec functions? Is there a specific way to ensure the HTTP request gets sent only if the previous tests pass? Do I just need to add it after my tests? |
Beta Was this translation helpful? Give feedback.
-
creativiii:
I’d probably just use
creativiii:
If your test step returns a non-zero exit code so the Actions runner will consider it failed, yes. A step that doesn’t set another If the test exit status doesn’t work I’d suggest fixing that, but you could also check for it some other way and write your own |
Beta Was this translation helpful? Give feedback.
-
Amazing! Thank you for all the help, I’ll try implementing this over the weekend :slight_smile: |
Beta Was this translation helpful? Give feedback.
-
I’m almost done but I can’t seem to be able to run a curl command from my Github Actions:
Github is telling me "
This works on my local machine so I’m not sure why it wouldn’t here. |
Beta Was this translation helpful? Give feedback.
-
First off, I’ve recently seen a report of off-by-one errors on syntax error reporting in Github Actions. Not sure if that’s been fixed yet, so I’d recommend looking at lines 28 (looks good to me, though redundant) and 30 as well. A thing you could try to make sure that the quotes aren’t confusing the YAML parser would be to use a YAML block string:
However I see two other issues:
|
Beta Was this translation helpful? Give feedback.
I’d probably just use
curl
, but sure!If your test step returns a non-zero exit code so the Actions runner will consider it failed, yes. A step that doesn’t set another
if:
condition in the step definition won’t run after a previous failed step.If the test exit status doesn’t work I’d suggest fixing that, but you could also check for it some other way and write your own
if:
condition for the deploy step.