Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using composite action #46

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/actions/galaxy-social/action.yml
Original file line number Diff line number Diff line change
@@ -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"
50 changes: 14 additions & 36 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
59 changes: 14 additions & 45 deletions .github/workflows/publish_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins:
enabled: false
config:
base_url: "https://bsky.social"
username: $BLUESKY_USERNAME
username: ""
password: $BLUESKY_PASSWORD
max_content_length: 300

Expand All @@ -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
Expand Down