From 4800ad53dc7f616e08672e0ea10f3c71763ecdf8 Mon Sep 17 00:00:00 2001 From: Dimitrij Date: Fri, 15 Aug 2025 13:08:32 +0100 Subject: [PATCH] Create post_2_Reddit.yml bump --- .github/workflows/post_2_Reddit.yml | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/post_2_Reddit.yml diff --git a/.github/workflows/post_2_Reddit.yml b/.github/workflows/post_2_Reddit.yml new file mode 100644 index 00000000..14a07fbd --- /dev/null +++ b/.github/workflows/post_2_Reddit.yml @@ -0,0 +1,49 @@ +name: Post to Reddit via PowerShell + +on: + workflow_dispatch: + +jobs: + post: + runs-on: windows-latest + steps: + - name: Authenticate and post to Reddit + shell: pwsh + env: + CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }} + CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }} + USERNAME: ${{ secrets.REDDIT_USERNAME }} + PASSWORD: ${{ secrets.REDDIT_PASSWORD }} + SUBREDDIT: ${{ secrets.REDDIT_SUBREDDIT }} + run: | + # Step 1: Get access token + $authHeaders = @{ + Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$env:CLIENT_ID:$env:CLIENT_SECRET")) + "User-Agent" = "github-to-reddit-pwsh/0.1" + } + + $authBody = @{ + grant_type = "password" + username = $env:USERNAME + password = $env:PASSWORD + } + + $authResponse = Invoke-RestMethod -Uri "https://www.reddit.com/api/v1/access_token" -Method Post -Headers $authHeaders -Body $authBody + $token = $authResponse.access_token + + # Step 2: Post to subreddit + $postHeaders = @{ + Authorization = "bearer $token" + "User-Agent" = "github-to-reddit-pwsh/0.1" + } + + $postBody = @{ + sr = $env:SUBREDDIT + title = "Hello from GitHub Actions (PowerShell)" + kind = "self" + text = "This post was made using PowerShell in GitHub Actions." + } + + $postResponse = Invoke-RestMethod -Uri "https://oauth.reddit.com/api/submit" -Method Post -Headers $postHeaders -Body $postBody + Write-Host "Posted: $($postResponse.json.url)" +