-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
215dbf6
commit e1f5d86
Showing
7 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: bsky | ||
|
||
on: | ||
schedule: | ||
- cron: '12 13 * * 1' | ||
workflow_dispatch: | ||
|
||
|
||
jobs: | ||
post: | ||
runs-on: windows-latest | ||
env: | ||
BSKY_APP_PASS: ${{ secrets.BSKY_APP_PASS}} | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: 'renv' | ||
- uses: r-lib/actions/setup-renv@v2 | ||
with: | ||
cache-version: 1 | ||
- name: Post to Bluesky. | ||
run: Rscript runner-bsky.R | ||
- name: Save skeet result. | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: bsky_result | ||
path: bsky_result.rds |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: reskeet | ||
|
||
permissions: | ||
actions: read | ||
contents: read | ||
|
||
on: | ||
schedule: | ||
- cron: '30 12 * * 2' | ||
workflow_dispatch: | ||
|
||
|
||
jobs: | ||
post: | ||
runs-on: windows-latest | ||
env: | ||
BSKY_DSLC: ${{ secrets.BSKY_DSLC}} | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Fetch the latest successful run ID from bsky workflow | ||
shell: pwsh | ||
run: | | ||
$headers = @{ | ||
"Authorization" = "token ${{ secrets.GITHUB_TOKEN }}" | ||
} | ||
$uri = "https://api.github.com/repos/rfordatascience/ttpost/actions/workflows/bsky.yml/runs?status=success&branch=main&per_page=1" | ||
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers | ||
$run_id = $response.workflow_runs[0].id.ToString().Trim() | ||
echo "Latest run ID: $run_id" | ||
echo "RUN_ID=$run_id" | Out-File -FilePath $env:GITHUB_ENV -Append | ||
- name: Grab the artifact ID from that run | ||
shell: pwsh | ||
run: | | ||
$headers = @{ | ||
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}" | ||
"Accept" = "application/vnd.github.v3+json" | ||
} | ||
$uri = "https://api.github.com/repos/rfordatascience/ttpost/actions/runs/${{ env.RUN_ID }}/artifacts" | ||
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers | ||
Write-Output "Artifacts available:" | ||
$response.artifacts | ForEach-Object { | ||
Write-Output "Artifact Name: $($_.name), Artifact ID: $($_.id)" | ||
echo "ARTIFACT_ID=$($_.id)" | Out-File -FilePath $env:GITHUB_ENV -Append | ||
} | ||
- name: Download post ID artifact | ||
shell: pwsh | ||
run: | | ||
$headers = @{ | ||
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}" | ||
"Accept" = "application/vnd.github.v3+json" | ||
} | ||
$artifactId = $env:ARTIFACT_ID | ||
$artifactUrl = "https://api.github.com/repos/rfordatascience/ttpost/actions/artifacts/$artifactId/zip" | ||
Write-Host "Downloading artifact ID: $artifactId from URL: $artifactUrl" | ||
Invoke-RestMethod -Uri $artifactUrl -Method Get -Headers $headers -OutFile "li_post_id.zip" | ||
Write-Host "Artifact downloaded successfully to 'li_post_id.zip'." | ||
Expand-Archive -LiteralPath "li_post_id.zip" -DestinationPath "." -Force | ||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: 'renv' | ||
- uses: r-lib/actions/setup-renv@v2 | ||
with: | ||
cache-version: 1 | ||
- name: Repost on Bluesky. | ||
run: Rscript dslc-reskeet.R |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
source("helpers-bsky.R", local = TRUE) | ||
|
||
bsky_result <- readRDS("bsky_result.rds") | ||
|
||
if (attr(bsky_result, "week") != lubridate::week(lubridate::now())) { | ||
stop("The bsky result was not generated this week. Stopping.") | ||
} | ||
|
||
attr(bsky_result, "week") <- NULL | ||
|
||
post_uri <- bsky_result$uri | ||
|
||
bskyr::set_bluesky_user("dslc.io") | ||
bskyr::set_bluesky_pass(Sys.getenv("BSKY_DSLC")) | ||
bskyr::bs_auth(bskyr::get_bluesky_user(), bskyr::get_bluesky_pass(), NULL) | ||
|
||
bskyr::bs_like(post_uri) | ||
|
||
reskeet_msg <- paste( | ||
"It's #TidyTuesday y'all! Show us what you made on our Slack at https://dslc.io!", | ||
"#RStats #PyData #JuliaLang #RustLang #DataViz #DataScience #DataAnalytics #data #tidyverse #DataBS", | ||
sep = "\n" | ||
) | ||
|
||
result <- bskyr::bs_post( | ||
reskeet_msg, | ||
quote = post_uri | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
tt_skeet <- function(status_msg, img_paths, alt_text) { | ||
result <- bskyr::bs_post( | ||
text = status_msg, | ||
images = img_paths, | ||
images_alt = alt_text | ||
) | ||
if (result$validation_status[[1]] != "valid") { | ||
stop("Bluesky broke!") | ||
} | ||
|
||
return(result) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Do the common tasks. | ||
source("runner-shared.R", local = TRUE) | ||
|
||
# Skeet. | ||
source("helpers-bsky.R", local = TRUE) | ||
|
||
bsky_msg_start <- stringr::str_replace( | ||
status_msg_start, | ||
"https://DSLC.io welcomes you", | ||
"@dslc.io welcomes you" | ||
) | ||
|
||
bsky_msg <- paste(bsky_msg_start, status_msg_end, sep = "\n") | ||
|
||
if (nchar(article_msg) + nchar(bsky_msg) < 300) { | ||
bsky_msg_start <- paste(bsky_msg_start, article_msg, sep = "\n") | ||
bsky_msg <- paste(bsky_msg_start, status_msg_end, sep = "\n") | ||
} | ||
|
||
if (length(metadata$credit$bluesky)) { | ||
bsky_credit <- stringr::str_replace( | ||
metadata$credit$bluesky, | ||
"https://bsky.app/profile/", | ||
"@" | ||
) | ||
credit <- glue::glue("Curator: {bsky_credit}") | ||
maybe_msg <- paste( | ||
credit, bsky_msg, sep = "\n" | ||
) | ||
if (length(credit) && (nchar(maybe_msg) <= 300)) { | ||
bsky_msg <- maybe_msg | ||
} | ||
} | ||
|
||
bskyr::set_bluesky_user("jonthegeek.com") | ||
bskyr::set_bluesky_pass(Sys.getenv("BSKY_APP_PASS")) | ||
bskyr::bs_auth(bskyr::get_bluesky_user(), bskyr::get_bluesky_pass(), NULL) | ||
|
||
result <- tt_skeet(bsky_msg, img_paths, alt_text) | ||
|
||
attr(result, "week") <- lubridate::week(lubridate::now()) | ||
saveRDS(result, "bsky_result.rds") |
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