-
Notifications
You must be signed in to change notification settings - Fork 109
[AI HACKATHON TEST - DO NOT MERGE] Files with NO metadata #432
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --- | ||
| ########################### | ||
| ########################### | ||
| ## Deployment AI generation testing ## | ||
| ########################### | ||
| ########################### | ||
|
|
||
| name: Hackathon Deployment Request | ||
|
|
||
| ###################################################### | ||
| # Start the job on a "deployment" to hackathon-test or other branch # | ||
| ###################################################### | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| target_branch: | ||
| description: "Target branch to send PR to (e.g., main, stage, etc)" | ||
| type: string | ||
| required: false | ||
| default: "hackathon-test" | ||
|
|
||
| ############### | ||
| # Set the Job # | ||
| ############### | ||
|
|
||
| jobs: | ||
| ai-metadata-update: | ||
| name: AI Metadata Update on Deployment | ||
| uses: AdobeDocs/adp-devsite-workflow/.github/workflows/ai-deploy-metadata.yml@app-builder-test | ||
| with: | ||
| FILE_NAME: "all_pages_content.txt" | ||
| secrets: | ||
| AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }} | ||
| AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} | ||
|
|
||
| lint: | ||
| name: Lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Lint | ||
| run: npx --yes github:AdobeDocs/adp-devsite-utils#add-lint-check runLint -v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| ########################### | ||
| ########################### | ||
| ## Pull request testing ## | ||
| ########################### | ||
| ########################### | ||
| name: Hackathon Pull Request | ||
|
|
||
| # Documentation: | ||
| # - Workflow: https://help.github.com/en/articles/workflow-syntax-for-github-actions | ||
| # - SuperLinter: https://github.com/github/super-linter | ||
| # - Markdown linter: https://github.com/DavidAnson/markdownlint | ||
| # - Link validation: https://github.com/remarkjs/remark-validate-links | ||
|
|
||
| ###################################################### | ||
| # Start the job on a pull request to the hackathon-test branch # | ||
| ###################################################### | ||
| on: | ||
| pull_request: | ||
| branches: [hackathon-test] | ||
| paths: | ||
| - 'src/pages/**' | ||
|
|
||
| ############### | ||
| # Set the Job # | ||
| ############### | ||
| jobs: | ||
| call_reusable_workflow: | ||
| name: Generate AI Metadata | ||
| # Skip if PR title starts with "[AI PR] Metadata Update" or branch name starts with "ai-metadata" | ||
| if: >- | ||
| !startsWith(github.event.pull_request.title, '[AI PR] Metadata Update') || | ||
| !startsWith(github.event.pull_request.head.ref, 'ai-metadata') | ||
| uses: AdobeDocs/adp-devsite-workflow/.github/workflows/ai-pr-request-metadata.yml@app-builder-test | ||
| with: | ||
| PR_ID: ${{ github.event.pull_request.number }} | ||
| FILE_NAME: "pr_content.txt" | ||
| secrets: | ||
| AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }} | ||
| AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Lesson 2: Writing a Serverless Action | ||
|
|
||
| There are many existing npm packages to display a barcode. Some don't play well in serverless environments. | ||
| For this Code Lab, we'll use [bwip-js](https://www.npmjs.com/package/bwip-js/) to render a code128 barcode. | ||
|
|
||
| ## Barcode action | ||
|
|
||
| First, install the dependency with: | ||
|
|
||
| ```bash | ||
| npm i bwip-js --save | ||
| ``` | ||
|
|
||
| Then import the dependency into your action: | ||
|
|
||
| ```javascript | ||
| const bwipjs = require('bwip-js'); | ||
| ``` | ||
|
|
||
| Now we can use the library and generate a barcode buffer in the exported main function: | ||
|
|
||
| ```javascript | ||
| const buffer = await bwipjs.toBuffer({ | ||
| bcid: 'code128', | ||
| text: params.value, | ||
| scale: 3, | ||
| height: 10, | ||
| includetext: false, | ||
| }); | ||
| ``` | ||
|
|
||
| Notice that we defined a `value` parameter to be passed to the barcode generator configuration. This is the actual data that the barcode will be holding. | ||
|
|
||
| Then we can return the image representation of the buffer with: | ||
|
|
||
| ```javascript | ||
| return { | ||
| headers: { 'Content-Type': 'image/png' }, | ||
| statusCode: 200, | ||
| body: buffer.toString('base64') | ||
| }; | ||
| ``` | ||
|
|
||
| Finally we can add checks to verify the requested `value` parameter, add logging and appropriate error handling to obtain this action: | ||
|
|
||
| ```javascript | ||
| const { Core } = require('@adobe/aio-sdk'); | ||
| const { errorResponse, stringParameters, checkMissingRequestInputs } = require('../utils'); | ||
| const bwipjs = require('bwip-js'); | ||
|
|
||
| // main function that will be executed by Adobe I/O Runtime | ||
| async function main (params) { | ||
| // create a Logger | ||
| const logger = Core.Logger('main', { level: params.LOG_LEVEL || 'info' }); | ||
|
|
||
| try { | ||
| // 'info' is the default level if not set | ||
| logger.info('Calling the main action'); | ||
|
|
||
| // log parameters, only if params.LOG_LEVEL === 'debug' | ||
| logger.debug(stringParameters(params)); | ||
|
|
||
| // check for missing request input parameters and headers | ||
| const requiredParams = ['value']; | ||
| const errorMessage = checkMissingRequestInputs(params, requiredParams); | ||
| if (errorMessage) { | ||
| // return and log client errors | ||
| return errorResponse(400, errorMessage, logger); | ||
| } | ||
|
|
||
| const buffer = await bwipjs.toBuffer({ | ||
| bcid: 'code128', | ||
| text: params.value, | ||
| scale: 3, | ||
| height: 10, | ||
| includetext: false, | ||
| backgroundcolor: 'ffffff' | ||
| }); | ||
|
|
||
| return { | ||
| headers: { 'Content-Type': 'image/png' }, | ||
| statusCode: 200, | ||
| body: buffer.toString('base64') | ||
| }; | ||
| } catch (error) { | ||
| // log any server errors | ||
| logger.error(error); | ||
| // return with 500 | ||
| return errorResponse(500, error.message, logger); | ||
| } | ||
| } | ||
|
|
||
| exports.main = main; | ||
| ``` | ||
|
|
||
| You can run the action locally using the CLI using: | ||
|
|
||
| ```bash | ||
| aio app run --local | ||
| ``` | ||
|
|
||
| This will: | ||
|
|
||
| 1. Start a local [OpenWhisk](https://openwhisk.apache.org/) stack on Docker | ||
| 2. Package and deploy the Runtime action and its dependencies using a built-in webpack configuration | ||
| 3. Start a local development environment and provide the action url e.g. `http://localhost:3233/api/v1/web/guest/my-barcode-app-0.0.1/barcode` for testing and debugging | ||
|
|
||
| Note that we'll cover how to do debug an App Builder app in a different Code Lab. | ||
|
|
||
| Nowadd the value parameter, e.g. `?value=test`, to the url so the action will generate a barcode: | ||
|
|
||
|  | ||
|
|
||
| ## Deploying | ||
|
|
||
| You can deploy an App Builder Headless app with `aio app run` or `aio app deploy`. This will deploy the actions to Adobe I/O Runtime. | ||
| `aio app deploy` would have deployed the UI to a CDN, but since we don't have a UI, that step is ignored. We'll have a separate Code Lab to guide you through building an App Builder App with UI. | ||
|
|
||
| Be sure to set your Adobe I/O Runtime secrets (namespace and auth) in the `.env` file. Also, turn off the built-in authentication by setting `require-adobe-auth: false` in the `manifest.yml`. The security topic will be covered in a dedicated Code Lab. | ||
|
|
||
| Entering deploy in the CLI will output the deployed action URL: | ||
|
|
||
|  | ||
|
|
||
| **Congratulations! Your first App Builder Headless App is live.** | ||
|
|
||
| How can we test that the passed value is actually rendered as a barcode? Fortunately, there are barcode readers that we can use in our tests. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.