diff --git a/.github/workflows/add-mods-of-the-month.yml b/.github/workflows/add-mods-of-the-month.yml index 6d8248b..15cfc21 100644 --- a/.github/workflows/add-mods-of-the-month.yml +++ b/.github/workflows/add-mods-of-the-month.yml @@ -13,11 +13,37 @@ on: default: '' required: true type: string - date: - description: 'UNIX timestamp (optional, used instead of current date)' - default: '' - required: false - type: string + month: + description: 'Month of video' + required: true + default: 'January' + type: choice + options: + - 'January' + - 'February' + - 'March' + - 'April' + - 'May' + - 'June' + - 'July' + - 'August' + - 'September' + - 'October' + - 'November' + - 'December' + year: + description: 'Year of video' + required: true + default: '2024' + type: choice + options: + - '2024' + - '2025' + - '2026' + - '2027' + - '2028' + - '2029' + - '2030' # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -28,7 +54,8 @@ jobs: env: EXT_MOTM_LINK: ${{ inputs.link }} - EXT_MOTM_DATE: ${{ inputs.date }} + EXT_MOTM_MONTH: ${{ inputs.month }} + EXT_MOTM_YEAR: ${{ inputs.year }} # Steps represent a sequence of tasks that will be executed as part of the job steps: diff --git a/src/add-mods-of-month.ts b/src/add-mods-of-month.ts index f1f64d1..f748954 100644 --- a/src/add-mods-of-month.ts +++ b/src/add-mods-of-month.ts @@ -14,21 +14,34 @@ const MOTM_ARCHIVE_PATH: string = path.join(REPO_ROOT_PATH, 'archive'); // env variables const EXT_MOTM_LINK = process.env.EXT_MOTM_LINK || ''; -const EXT_MOTM_DATE = process.env.EXT_MOTM_DATE || ''; +const EXT_MOTM_MONTH = process.env.EXT_MOTM_MONTH || ''; +const EXT_MOTM_YEAR = process.env.EXT_MOTM_YEAR || ''; + +const MONTH_DICT: { [key: string]: number } = { + 'January': 1, + 'February': 2, + 'March': 3, + 'April': 4, + 'May': 5, + 'June': 6, + 'July': 7, + 'August': 8, + 'September': 9, + 'October': 10, + 'November': 11, + 'December': 12 +} async function start() { console.log('Start Program'); - if (EXT_MOTM_LINK === '') { - console.error('No EXT_MOTM_LINK found in env'); - process.exit(1); - } - - if (EXT_MOTM_DATE !== '' && isNaN(+EXT_MOTM_DATE)) { - console.error('EXT_MOTM_DATE is not a unix timestamp number'); - process.exit(1); - } + [EXT_MOTM_LINK, EXT_MOTM_MONTH, EXT_MOTM_YEAR].forEach((envVar) => { + if (envVar === '') { + console.error(`No ${envVar} found in env`); + process.exit(1); + } + }); const driver = new Driver(); await driver.process(); @@ -70,11 +83,13 @@ class Driver { public async process() { - console.log('main env variables', { EXT_MOTM_LINK, EXT_MOTM_DATE }); + console.log('main env variables', { EXT_MOTM_LINK, EXT_MOTM_MONTH, EXT_MOTM_YEAR }); console.log('Processing MOTM...'); this.mEntries = await this.readMOTMFile(); + const timestampMS = new Date(+EXT_MOTM_YEAR, MONTH_DICT[EXT_MOTM_MONTH]).getTime(); + const date = Math.floor(timestampMS / 1000); const newEntry: IMOTMEntry = { - date: !!EXT_MOTM_DATE ? +EXT_MOTM_DATE : Date.now(), + date, id: nanoid.nanoid(), videoid: this.extractVideoIdFromYouTubeUrl(EXT_MOTM_LINK) }