Conteudo #38
This file contains 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
name: Conteudo | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
jobs: | |
update-motivational-page: | |
runs-on: ubuntu-latest | |
environment: github-pages | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: IA | |
id: generate_text | |
run: | | |
echo "Chamada API" | |
API_KEY=${{ secrets.IA_API_KEY }} | |
RESPONSE=$(curl -s -X POST https://api.groq.com/openai/v1/chat/completions \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $API_KEY" \ | |
-d '{ | |
"model": "llama3-8b-8192", | |
"messages": [{"role": "user", "content": "Generate encouraging writing text about technology or programming, no longer than 35 lines and family friendly, write like a report."}] | |
}') | |
MOTIVATIONAL_TEXT=$(echo "$RESPONSE" | jq -r '.choices[0].message.content') | |
if [ -z "$MOTIVATIONAL_TEXT" ]; then | |
MOTIVATIONAL_TEXT="Well, it's not perfect, but it's definitely something!" | |
fi | |
ESCAPED_TEXT=$(echo "$MOTIVATIONAL_TEXT" | sed 's/[&/\"]/\\&/g') | |
ESCAPED_TEXT=$(echo "$ESCAPED_TEXT" | sed 's|/|\\/|g' | sed 's|"|\\"|g') | |
if grep -q '<div id="motivational-text">' index.html; then | |
sed -i "s|<div id=\"motivational-text\">.*</div>|<div id=\"motivational-text\">$ESCAPED_TEXT</div>|" index.html | |
else | |
sed -i "/<body>/a <div id=\"motivational-text\">$ESCAPED_TEXT</div>" index.html | |
fi | |
echo "<!-- set in $(date) -->" >> index.html | |
- name: cat | |
run: cat index.html | |
- name: Commit & Push | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add index.html | |
git commit -m "Keep Devoping" | |
git push origin main | |
- name: Config | |
uses: actions/configure-pages@v2 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: arti | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: './' | |
- name: Publish | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} |