diff --git a/.github/workflows/post-sns.yml b/.github/workflows/post-sns.yml new file mode 100644 index 00000000..c8011976 --- /dev/null +++ b/.github/workflows/post-sns.yml @@ -0,0 +1,79 @@ +name: Post SNS + +on: + pull_request: + types: [closed] + branches: + - main + +jobs: + post-sns: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'sns') + runs-on: ubuntu-latest + steps: + # https://github.com/actions/checkout + - uses: actions/checkout@v4 + + # https://github.com/actions/setup-node + - uses: actions/setup-node@v4 + with: + node-version: '20' # Updated to latest LTS version + + # https://github.com/plhery/node-twitter-api-v2 + # https://github.com/linkedin-developers/linkedin-api-js-client#linkedin-api-javascript-client + - name: Install dependencies + run: | + npm install twitter-api-v2 + npm install linkedin-api-client + + # https://github.com/actions/github-script + - name: Post to X + uses: actions/github-script@v7 + with: + script: | + const { TwitterApi } = require('twitter-api-v2'); + const client = new TwitterApi({ + appKey: process.env.TWITTER_API_KEY, + appSecret: process.env.TWITTER_API_SECRET, + accessToken: process.env.TWITTER_ACCESS_TOKEN, + accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET, + }); + + const tweet = `🚀 New release: ${context.payload.pull_request.title}\n\n${context.payload.pull_request.html_url}`; + + // https://developer.x.com/en/docs/x-api/tweets/manage-tweets/api-reference/post-tweets + await client.v2.tweet(tweet); + env: + TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }} + TWITTER_API_SECRET: ${{ secrets.TWITTER_API_SECRET }} + TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} + + - name: Post to LinkedIn + uses: actions/github-script@v7 + with: + script: | + const { RestliClient } = require('linkedin-api-client'); + const restliClient = new RestliClient(); + + // Create post using Posts API + // https://learn.microsoft.com/en-us/linkedin/marketing/community-management/shares/posts-api?view=li-lms-2024-11&viewFallbackFrom=li-lms-unversioned&tabs=http + const post = await restliClient.create({ + resourcePath: '/posts', + entity: { + author: 'urn:li:organization:100932100', + commentary: `🚀 New release: ${context.payload.pull_request.title}\n\n${context.payload.pull_request.html_url}`, + visibility: 'PUBLIC', + distribution: { + feedDistribution: 'MAIN_FEED', + targetEntities: [], + thirdPartyDistributionChannels: [] + }, + lifecycleState: 'PUBLISHED', + isReshareDisabledByAuthor: false + }, + accessToken: process.env.LINKEDIN_ACCESS_TOKEN + }); + env: + LINKEDIN_ACCESS_TOKEN: ${{ secrets.LINKEDIN_ACCESS_TOKEN }} + diff --git a/.github/workflows/x-post-draft.yml b/.github/workflows/x-post-draft.yml deleted file mode 100644 index 63932b15..00000000 --- a/.github/workflows/x-post-draft.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Create X Post Draft - -on: - pull_request: - types: [closed] - branches: - - main - -jobs: - create-x-post-draft: - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - # https://github.com/actions/checkout - - uses: actions/checkout@v4 - - # https://github.com/actions/setup-node - - uses: actions/setup-node@v4 - with: - node-version: '20' # Updated to latest LTS version - - # https://github.com/plhery/node-twitter-api-v2 - - name: Install dependencies - run: npm install twitter-api-v2 - - # https://github.com/actions/github-script - - name: Create X Post Draft - uses: actions/github-script@v7 - with: - script: | - const { TwitterApi } = require('twitter-api-v2'); - - // Initialize with OAuth 1.0a credentials - const client = new TwitterApi({ - appKey: process.env.TWITTER_API_KEY, - appSecret: process.env.TWITTER_API_SECRET, - accessToken: process.env.TWITTER_ACCESS_TOKEN, - accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET, - }); - - const tweet = `🚀 New release: ${context.payload.pull_request.title}\n\n${context.payload.pull_request.html_url}`; - - // https://developer.x.com/en/docs/x-api/tweets/manage-tweets/api-reference/post-tweets - await client.v2.tweet(tweet); - env: - TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }} - TWITTER_API_SECRET: ${{ secrets.TWITTER_API_SECRET }} - TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} - TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} -