Skip to content

Commit ee59d4d

Browse files
committed
first commit
0 parents  commit ee59d4d

File tree

691 files changed

+132512
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

691 files changed

+132512
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Schedule Attendance Marking
2+
3+
on:
4+
schedule:
5+
- cron: '0 13 * * 2-6' # Monday to Friday at 08:00 Lima (13:00 UTC) → In
6+
- cron: '0 0 * * 2-5' # Monday to Thursday at 19:00 Lima (00:00 UTC) → Out
7+
- cron: '0 22 * * 6' # Friday at 17:00 Lima (22:00 UTC) → Out
8+
workflow_dispatch: # Allows manual execution
9+
10+
jobs:
11+
set-attendance-type:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
attendance_type: ${{ steps.set-type.outputs.ATTENDANCE_TYPE }}
15+
16+
steps:
17+
# Determine the attendance type based on the current UTC hour
18+
- name: Determine attendance type
19+
id: set-type
20+
run: |
21+
HOUR_UTC=$(date -u +%H)
22+
if [[ "$HOUR_UTC" -lt 18 ]]; then
23+
echo "ATTENDANCE_TYPE=In" >> $GITHUB_OUTPUT
24+
else
25+
echo "ATTENDANCE_TYPE=Out" >> $GITHUB_OUTPUT
26+
fi
27+
28+
mark-attendance:
29+
runs-on: ubuntu-latest
30+
needs: set-attendance-type
31+
32+
steps:
33+
# Checkout the repository to use this private action
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
37+
# Set up Chrome browser, ChromeDriver, and dependencies
38+
- name: Set up Chrome
39+
uses: browser-actions/setup-chrome@v1
40+
id: setup-chrome
41+
with:
42+
chrome-version: stable
43+
install-chromedriver: true
44+
install-dependencies: true
45+
46+
# Use the custom javascript action to mark attendance based on the determined type
47+
- name: Mark Attendance
48+
uses: cbecerrae/talana-attendance-javascript-action@v1
49+
id: mark-attendance
50+
with:
51+
attendance_email: ${{ secrets.ATTENDANCE_EMAIL }}
52+
attendance_password: ${{ secrets.ATTENDANCE_PASSWORD }}
53+
attendance_type: ${{ needs.set-attendance-type.outputs.attendance_type }}
54+
chrome_path: ${{ steps.setup-chrome.outputs.chrome-path }}
55+
chromedriver_path: ${{ steps.setup-chrome.outputs.chromedriver-path }}
56+
57+
# Confirm the attendance marking and output the attendance type and time
58+
- name: Confirm Attendance
59+
run: echo "Attendance of type '${{ needs.set-attendance-type.outputs.attendance_type }}' marked at time ${{ steps.mark-attendance.outputs.attendance_time }}"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Cristhian Alonzo Becerra Espinoza
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Talana Attendance JavaScript Action
2+
3+
This GitHub Action automates attendance marking on the [Talana](https://peru.talana.com/es-pe/remuneraciones/login-vue#/) platform using JavaScript, Node.js, and Selenium. It runs on a schedule, logging in and marking attendance as "In" or "Out" based on the time, leveraging Selenium to interact with the platform. The action ensures seamless, automated attendance marking.
4+
5+
## Requirements
6+
7+
To use this action, you need *Google Chrome* and *ChromeDriver* installed on the runner. You can install them using the [setup-chrome](https://github.com/browser-actions/setup-chrome) GitHub Action. This action automatically provides the necessary paths to the Chrome and ChromeDriver binaries. These paths should be passed as inputs (`chrome_path` and `chromedriver_path`) to the **talana-attendance-javascript-action** GitHub Action.
8+
9+
## Inputs
10+
11+
### `attendance_email`
12+
13+
**Required** User email for authentication.
14+
15+
### `attendance_password`
16+
17+
**Required** User password for authentication.
18+
19+
### `attendance_type`
20+
21+
**Required** Attendance type: In or Out.
22+
23+
### `chrome_path`
24+
25+
**Required** Path to the installed Chrome binary.
26+
27+
### `chromedriver_path`
28+
29+
**Required** Path to the installed ChromeDriver binary.
30+
31+
## Outputs
32+
33+
### `attendance_time`
34+
35+
The time when the attendance was marked.
36+
37+
## Usage
38+
39+
```yaml
40+
uses: cbecerrae/talana-attendance-javascript-action@v1
41+
with:
42+
attendance_email: 'user@example.com'
43+
attendance_password: 'password123'
44+
attendance_type: 'In'
45+
chrome_path: '/path/to/chrome'
46+
chromedriver_path: '/path/to/chromedriver'
47+
```
48+
49+
## GitHub Action Workflow Example
50+
51+
[![Schedule Attendance Marking](https://github.com/cbecerrae/talana-attendance-javascript-action/actions/workflows/schedule-attendance.yml/badge.svg)](https://github.com/cbecerrae/talana-attendance-javascript-action/actions/workflows/schedule-attendance.yml)
52+
53+
For a full example of how to implement this action alongside **setup-chrome**, check the [`.github/workflows/schedule-attendance.yml`](.github/workflows/schedule-attendance.yml) file. This example demonstrates how to schedule attendance marking and provides a working setup for using this action in combination with the **setup-chrome** action.

action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'Talana Attendance JavaScript Action'
2+
description: 'This GitHub Action automates attendance marking in Talana by interacting with the platform using Node.js and Selenium.'
3+
inputs:
4+
attendance_email:
5+
description: 'User email for authentication'
6+
required: true
7+
attendance_password:
8+
description: 'User password for authentication'
9+
required: true
10+
attendance_type:
11+
description: 'Attendance type: In or Out'
12+
required: true
13+
chrome_path:
14+
description: 'Path to the installed Chrome binary'
15+
required: true
16+
chromedriver_path:
17+
description: 'Path to the installed ChromeDriver binary'
18+
required: true
19+
outputs:
20+
attendance_time:
21+
description: 'The time when the attendance was marked'
22+
23+
runs:
24+
using: 'node20'
25+
main: 'index.js'
26+
27+
branding:
28+
icon: 'clock'
29+
color: 'green'

index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const core = require('@actions/core');
2+
const { getDriver } = require('./utils/chrome.js');
3+
const { login } = require('./utils/login.js');
4+
const { markAttendance } = require('./utils/mark_attendance.js');
5+
const { logger } = require('./utils/shared.js');
6+
7+
async function main() {
8+
/**
9+
* Main function that executes the attendance marking process.
10+
*
11+
* This function is invoked by GitHub Actions and expects its input as environment variables.
12+
* It initializes a headless Chrome browser using Puppeteer, performs user authentication,
13+
* and marks attendance based on the specified type ('In' or 'Out').
14+
*
15+
* If an exception occurs during execution, it logs the error and exits with a non-zero status.
16+
*/
17+
18+
// Extract input parameters provided by GitHub Actions
19+
const email = core.getInput('attendance_email'); // User email for authentication
20+
const password = core.getInput('attendance_password'); // User password for authentication
21+
const type = core.getInput('attendance_type'); // Attendance type: 'In' or 'Out'
22+
const chromePath = core.getInput('chrome_path'); // Path to the Chrome binary
23+
const chromedriverPath = core.getInput('chromedriver_path'); // Path to the ChromeDriver binary
24+
25+
// Validate required parameters
26+
if (!email || !password || !type) {
27+
console.error('Missing required environment variables.');
28+
process.exit(1);
29+
}
30+
31+
// Launch a new ChromeDriver instance with the specified chromePath
32+
let driver = await getDriver(chromePath, chromedriverPath);
33+
34+
try {
35+
// Perform login operation
36+
await login(driver, email, password);
37+
38+
// Mark attendance based on the provided type
39+
await markAttendance(driver, type);
40+
} catch (error) {
41+
// Log any encountered errors
42+
logger.error(`Exception caught: ${error.message}`);
43+
logger.error(`Stack Trace: ${error.stack}`);
44+
process.exit(1);
45+
} finally {
46+
// Ensure the browser is closed to free up resources
47+
await driver.quit();
48+
}
49+
50+
// Set the output for the GitHub Actions workflow
51+
const time = (new Date()).toTimeString();
52+
core.setOutput("attendance_time", time);
53+
}
54+
55+
// Execute the main function when the script is run directly
56+
if (require.main === module) {
57+
main();
58+
}

0 commit comments

Comments
 (0)