Skip to content
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

Run password rules workflow on schedule #334

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions .github/workflows/password-rules.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
name: Password Rules

on:
pull_request:
types: [opened]
workflow_dispatch:
schedule:
- cron: '0 3 * * *' # every morning at 3am UTC

jobs:
test:
runs-on: ubuntu-20.04
update:
name: Get latest password rules
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- uses: actions/cache@v2
- name: Get latest rules
run: node ./packages/password/scripts/rules.js --write-rules-json
- name: Check for changes
id: changes
run: |
filesChanged=$(sh ./scripts/check-for-changes.sh)
if [ -z "$filesChanged" ]; then hasChanged="false"; else hasChanged="true"; fi
echo "hasChanged=$hasChanged" >> "$GITHUB_OUTPUT"
shell: bash {0}
- name: Get current date
id: date
run: |
echo "currentDate=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"
- name: Create PR for updated rules
if: ${{ steps.changes.outputs.hasChanged == 'true' }}
uses: peter-evans/create-pull-request@88bf0de51c7487d91e1abbb4899332e602c58bbf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to question the use of this - but then I realised it's used in the autofill automation already :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shakyShane Yeah, just copy-pasted the one we're using for the release flow 😁 -- I assume it's the version that's been checked and that we're good to use.

with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: actions/github-script@v6
with:
#language=javascript
script: |
const current = require('./packages/password/rules.json')
const {summary, intoMarkdown, REMOTE_URL} = require('./packages/password/scripts/rules.js')
const result = await github.request(REMOTE_URL);
const lines = summary(current, JSON.parse(result.data));

if (lines.length === 0) return;

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: intoMarkdown(lines),
})
add-paths: |
packages/password/rules.json
commit-message: Update password rules
branch: automated/update-password-rules-${{ steps.date.outputs.currentDate }}
title: "Update password rules (${{steps.date.outputs.currentDate}})"
body: "Updating password rules from remote source, pulled on ${{steps.date.outputs.currentDate}}"
token: ${{ secrets.DAXMOBILE_AUTOFILL_AUTOMATION }}
18 changes: 0 additions & 18 deletions packages/password/scripts/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ function download () {
})
}

/**
* @param {string[]} lines
*/
function intoMarkdown (lines) {
const header = '## Note: Password rules outdated'
const mainBody = '```\n' + lines.join('\n') + '\n```'
const updateTitle = '**You can update the rules with the following command**'
const updateCommand = '```sh\ncd packages/password && npm run rules:update\n```'
const footer = 'Once you\'ve updated the rules, re-run the build from the root with `npm run build` and then commit all changes.'
return [header, mainBody, updateTitle, updateCommand, footer].join('\n')
}

if (process.argv.includes('--write-rules-json')) {
download()
.then((remoteRules) => {
Expand All @@ -91,9 +79,3 @@ if (process.argv.includes('--write-rules-json')) {
process.exit(1)
})
}

module.exports.update = update
module.exports.summary = summary
module.exports.download = download
module.exports.intoMarkdown = intoMarkdown
module.exports.REMOTE_URL = REMOTE_URL
Loading