Here are four useful ways that GitHub helps improve your workflow.
If your code is hosted on Github, you can take advantage of the tasks that Github brings. Instead of running all tests and linters manually, we can take advantage of Github actions for these tasks.
Without any difficulties, here are 4 actions with Github that will save you time and improve your workflow. If you do not understand what Github actions are and how to use them, please stay here before proceeding with today’s article.
1. Check your website with Google Chrome’s Lighthouse Test
This action is a useful integration of Google’s Lighthouse Audit for websites, namely performance testing, accessibility, best practices, SEO and PWAs ( Progressive Web Application ).
Right now, the action will print five scores (within 100) of the output and upload the HTML and JSON versions of the report as evidence.
On the next release, this action will allow you to specify a threshold for each test and optionally not perform this step if they are not met.
Use
The following workflow performs a Lighthouse test on jarv.is , displays the five scores in the output of each step and uploads the results in .html and .json formats like the proof for download (like shown above).
Workflow.yml file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | name: Audit live site on: push jobs: audit: runs-on: ubuntu-latest steps: - name: Audit live URL uses: jakejarvis/ <a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="98f4f1fff0ecf0f7edebfdb5f9fbecf1f7f6d8f5f9ebecfdea">[email protected]</a> with: url: 'https://jarv.is/' - name: Upload results as an artifact uses: actions/ <a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="483d382427292c65293a3c212e292b3c0825293b3c2d3a">[email protected]</a> with: name: report path: './report' |
Lighthouse is really helpful when you build PWAs. Project is inspired by GoogleChromeLabs / lighthousebot .
2. Run SSH commands with GitHub Actions
This action will run the argument provided as a command on your $ HOST via SSH. This is really useful if you want to run commands on your private server after every commit or push.
Use
To use this useful, just add the following lines to .github/main.workflow
1 2 3 4 5 6 7 8 9 10 | action "Run deploy script" { uses = "maddox/actions/ <a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="1c6f6f745c717d6f68796e">[email protected]</a> " args = "/opt/deploy/run" secrets = [ "PRIVATE_KEY", "HOST", "USER" ] |
Argument requirements
The argument you will use is the command that will be run on your server via SSH.
For example
args = "/opt/deploy/run"
args = "touch ~/.reload"
Security requirements
You need to provide some confidential information to use actions:
PRIVATE_KEY
: Your private SSH key.HOST
: The action host will SSH to run the command. For example, your.site.com .USER
: SSH command users will authenticate as with the private key.
You can see the details at the Github repository .
3. Detect leak of secret keys – gitleaks-action
Git checks the secret commit with gitleaks
Use
1 2 3 4 5 6 7 8 | workflow "gitleaks my commits" { on = "push" resolves = ["gitleaks"] } action "gitleaks" { uses = "eshork/ <a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="6b0c021f070e0a0018460a081f0204052b060a181f0e19">[email protected]</a> " } |
Credibility from zricethezav / gitleaks for complex bits.
4. GitHub Action runs ESLint
This action executes the ESLint emulator on specified JavaScript files without any previous actions / build or Docker steps.
You must have ESLint running local for actions to be executed. It will use the same rules as you do locally. You can find more information at the ESLint getting started guide .
Use
Here is an example to make it work:
1 2 3 4 5 6 7 8 | workflow "New workflow" { on = "push" resolves = ["ESLint"] } action "ESLint" { uses = "stefanoeb/ <a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="4722342b2e29336a2624332e2829072a2634332235">[email protected]</a> " } |
By default, it will run ESLint through all files in the project. But you can also specify a range of files on arguments, like ESLint:
1 2 3 4 5 6 7 8 9 | workflow "New workflow" { on = "push" resolves = ["ESLint"] } action "ESLint" { uses = "stefanoeb/ <a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="442137282d2a30692527302d2b2a04292537302136">[email protected]</a> " args = "index.js src/**.js" } |
If not ̀ need any installation step before installing the module, actions will perform yarn install
or npm install
automatically.
Conclusion
I hope you have learned something new from your writing. If there are any Github Actions you know, share them to make the most of Github’s benefits.