relinkedin #12
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: relinkedin | |
permissions: | |
actions: read | |
contents: read | |
on: | |
schedule: | |
- cron: '30 12 * * 2' | |
workflow_dispatch: | |
jobs: | |
post: | |
runs-on: windows-latest | |
env: | |
LI_CLIENT_ID: ${{ secrets.LI_CLIENT_ID}} | |
LI_CLIENT_SECRET: ${{ secrets.LI_CLIENT_SECRET}} | |
LI_REFRESH_TOKEN: ${{ secrets.LI_REFRESH_TOKEN}} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Fetch the latest successful run ID from linkedin workflow | |
id: fetch_run_id | |
shell: pwsh | |
run: | | |
$headers = @{ | |
"Authorization" = "token ${{ secrets.GITHUB_TOKEN }}" | |
} | |
$uri = "https://api.github.com/repos/rfordatascience/ttpost/actions/workflows/linkedin.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: List artifacts for a workflow run | |
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 | |
} | |
shell: pwsh | |
- name: Download and inspect artifact using API | |
shell: pwsh | |
run: | | |
$headers = @{ | |
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}" | |
} | |
$artifactUrl = "https://api.github.com/repos/rfordatascience/ttpost/actions/artifacts/1418581898/zip" | |
$zipPath = "artifact.zip" | |
Invoke-RestMethod -Uri $artifactUrl -Method Get -Headers $headers -OutFile $zipPath | |
Write-Host "Artifact downloaded successfully." | |
# Create a directory to extract the contents | |
$extractPath = "extracted_artifact" | |
New-Item -ItemType Directory -Force -Path $extractPath | |
# Extract the artifact | |
Expand-Archive -LiteralPath $zipPath -DestinationPath $extractPath -Force | |
Write-Host "Artifact extracted. Listing contents:" | |
# List the contents of the extracted directory | |
Get-ChildItem -Path $extractPath -Recurse | |