diff --git a/.github/actions/galaxy-social/action.yml b/.github/actions/galaxy-social/action.yml new file mode 100644 index 0000000..dbe3025 --- /dev/null +++ b/.github/actions/galaxy-social/action.yml @@ -0,0 +1,71 @@ +name: Galaxy Social composite action +description: Perform common steps for getting changed files, setting up the environment, and running the main logic. +inputs: + files: + description: "File patterns to check for changes" + default: "posts/**" + + preview: + description: "Whether to create a preview or not" + default: "false" + +runs: + using: "composite" + steps: + - name: checkout #This is needed to avoid error on post action + uses: actions/checkout@v4 + + - name: Get changed files in posts folder + id: get_changed_files + uses: tj-actions/changed-files@v44 + with: + files: ${{ inputs.files }} + json: "true" + + - name: get published files cache + if: steps.get_changed_files.outputs.any_changed == 'true' + shell: bash + run: | + if ! git ls-remote --heads origin | grep -q "refs/heads/processed_files"; then + git checkout --orphan processed_files + git rm -rf . + echo "{}" > processed_files.json + git add processed_files.json + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + git commit -m "Initialize processed_files branch with processed_files.json" + git push origin processed_files + git checkout main + fi + git fetch origin processed_files:processed_files + git checkout processed_files -- processed_files.json + + - name: Set up Python + if: steps.get_changed_files.outputs.any_changed == 'true' + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + if: steps.get_changed_files.outputs.any_changed == 'true' + shell: bash + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements.txt + + - name: Run script to create preview + if: steps.get_changed_files.outputs.any_changed == 'true' && inputs.preview == 'true' + shell: bash + run: python -u github_run.py --preview + + - name: Run script to publish contents + if: steps.get_changed_files.outputs.any_changed == 'true' && inputs.preview == 'false' + shell: bash + run: python -u github_run.py --json-out processed_files.json + + - name: Commit changes + if: steps.get_changed_files.outputs.any_changed == 'true' && inputs.preview == 'false' + uses: stefanzweifel/git-auto-commit-action@v5 + with: + file_pattern: "processed_files.json" + branch: "processed_files" diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 880b8a0..0872219 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -4,53 +4,31 @@ on: pull_request_target: branches: [main] types: [opened, synchronize, reopened] + paths: + - "posts/**" jobs: preview: name: Preview runs-on: ubuntu-latest permissions: + contents: write pull-requests: write steps: - name: Checkout uses: actions/checkout@v4 - - name: Get changed files in posts folder - id: get_changed_files - uses: tj-actions/changed-files@v44 - with: - files: posts/** - json: "true" - - - name: get published files cache - if: steps.get_changed_files.outputs.any_changed == 'true' + - name: Set environment variables run: | - git fetch origin processed_files:processed_files - git checkout processed_files -- processed_files.json + echo "PR_NUMBER=${{ github.event.number }}" >> $GITHUB_ENV + echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + echo "MASTODON_ACCESS_TOKEN=${{ secrets.MASTODON_ACCESS_TOKEN }}" >> $GITHUB_ENV + echo "BLUESKY_PASSWORD=${{ secrets.BLUESKY_PASSWORD }}" >> $GITHUB_ENV + echo "MATRIX_ACCESS_TOKEN=${{ secrets.MATRIX_ACCESS_TOKEN }}" >> $GITHUB_ENV + echo "SLACK_ACCESS_TOKEN=${{ secrets.SLACK_ACCESS_TOKEN }}" >> $GITHUB_ENV + echo "MASTODON_EU_FR_TOKEN=${{ secrets.MASTODON_EU_FR_TOKEN }}" >> $GITHUB_ENV - - name: Set up Python - if: steps.get_changed_files.outputs.any_changed == 'true' - uses: actions/setup-python@v5 + - name: Run composite action + uses: ./.github/actions/galaxy-social with: - python-version: '3.12' - - - name: Install dependencies - if: steps.get_changed_files.outputs.any_changed == 'true' - run: | - python -m pip install --upgrade pip - python -m pip install -r requirements.txt - - - name: Run script to create preview - if: steps.get_changed_files.outputs.any_changed == 'true' - env: - MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} - BLUESKY_USERNAME: ${{ secrets.BLUESKY_USERNAME }} - BLUESKY_PASSWORD: ${{ secrets.BLUESKY_PASSWORD }} - MASTODON_EU_FR_TOKEN: ${{ secrets.MASTODON_EU_FR_TOKEN }} - MATRIX_ACCESS_TOKEN: ${{ secrets.MATRIX_ACCESS_TOKEN }} - SLACK_ACCESS_TOKEN: ${{ secrets.SLACK_ACCESS_TOKEN }} - SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }} - CHANGED_FILES: ${{ steps.get_changed_files.outputs.all_changed_files }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.number }} - run: python -u github_run.py --preview + preview: "true" diff --git a/.github/workflows/publish_content.yml b/.github/workflows/publish_content.yml index 9af8f3c..bc8617f 100644 --- a/.github/workflows/publish_content.yml +++ b/.github/workflows/publish_content.yml @@ -4,10 +4,13 @@ on: pull_request_target: branches: [main] types: [closed] + paths: + - "posts/**" jobs: publish: if: github.event.pull_request.merged == true + name: Publish content runs-on: ubuntu-latest permissions: contents: write @@ -16,49 +19,15 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Get changed files in posts folder - id: get_changed_files - uses: tj-actions/changed-files@v44 - with: - files: posts/** - json: "true" - - - name: get published files cache - if: steps.get_changed_files.outputs.any_changed == 'true' - run: | - git fetch origin processed_files:processed_files - git checkout processed_files -- processed_files.json - - - name: Set up Python - if: steps.get_changed_files.outputs.any_changed == 'true' - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - - name: Install dependencies - if: steps.get_changed_files.outputs.any_changed == 'true' + - name: Set environment variables run: | - python -m pip install --upgrade pip - python -m pip install -r requirements.txt - - - name: Run script to publish contents - if: steps.get_changed_files.outputs.any_changed == 'true' - env: - MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} - BLUESKY_USERNAME: ${{ secrets.BLUESKY_USERNAME }} - BLUESKY_PASSWORD: ${{ secrets.BLUESKY_PASSWORD }} - MASTODON_EU_FR_TOKEN: ${{ secrets.MASTODON_EU_FR_TOKEN }} - MATRIX_ACCESS_TOKEN: ${{ secrets.MATRIX_ACCESS_TOKEN }} - SLACK_ACCESS_TOKEN: ${{ secrets.SLACK_ACCESS_TOKEN }} - SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }} - CHANGED_FILES: ${{ steps.get_changed_files.outputs.all_changed_files }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.number }} - run: python -u github_run.py --json-out processed_files.json - - - name: Commit changes - if: steps.get_changed_files.outputs.any_changed == 'true' - uses: stefanzweifel/git-auto-commit-action@v5 - with: - file_pattern: "processed_files.json" - branch: "processed_files" + echo "PR_NUMBER=${{ github.event.number }}" >> $GITHUB_ENV + echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + echo "MASTODON_ACCESS_TOKEN=${{ secrets.MASTODON_ACCESS_TOKEN }}" >> $GITHUB_ENV + echo "BLUESKY_PASSWORD=${{ secrets.BLUESKY_PASSWORD }}" >> $GITHUB_ENV + echo "MATRIX_ACCESS_TOKEN=${{ secrets.MATRIX_ACCESS_TOKEN }}" >> $GITHUB_ENV + echo "SLACK_ACCESS_TOKEN=${{ secrets.SLACK_ACCESS_TOKEN }}" >> $GITHUB_ENV + echo "MASTODON_EU_FR_TOKEN=${{ secrets.MASTODON_EU_FR_TOKEN }}" >> $GITHUB_ENV + + - name: Run composite action + uses: ./.github/actions/galaxy-social diff --git a/plugins.yml b/plugins.yml index 689073d..14826ec 100644 --- a/plugins.yml +++ b/plugins.yml @@ -12,7 +12,7 @@ plugins: enabled: false config: base_url: "https://bsky.social" - username: $BLUESKY_USERNAME + username: "" password: $BLUESKY_PASSWORD max_content_length: 300 @@ -37,7 +37,7 @@ plugins: enabled: false config: access_token: $SLACK_ACCESS_TOKEN - channel_id: $SLACK_CHANNEL_ID + channel_id: "" max_content_length: 40000 - name: markdown