Publish and Tweet #40
Workflow file for this run
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: Publish and Tweet | |
on: | |
release: | |
types: | |
- created | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: set up python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: install | |
run: pip install -U build | |
- name: check version | |
id: check-tag | |
uses: samuelcolvin/check-python-version@v4.1 | |
with: | |
version_file_path: authx/__init__.py | |
- name: build | |
run: python -m build | |
- name: Upload package to PyPI | |
uses: pypa/gh-action-pypi-publish@v1.12.2 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
send-tweet: | |
name: Send Tweet | |
needs: [release] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Install dependencies | |
run: pip install tweepy==4.14.0 | |
- name: Send tweet | |
shell: python | |
run: | | |
import os | |
import re | |
from typing import Optional | |
import tweepy | |
def get_version(file_path: str = 'authx/__init__.py') -> Optional[str]: | |
version_pattern = r'__version__\s*=\s*"(?P<version>[\d\.]+)"' | |
try: | |
with open(file_path, 'r') as file: | |
content = file.read() | |
if match := re.search(version_pattern, content): | |
return match['version'] | |
except FileNotFoundError: | |
print(f"File {file_path} not found.") | |
return None | |
client = tweepy.Client( | |
access_token=os.getenv("TWITTER_ACCESS_TOKEN"), | |
access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET"), | |
consumer_key=os.getenv("TWITTER_CONSUMER_KEY"), | |
consumer_secret=os.getenv("TWITTER_CONSUMER_SECRET"), | |
) | |
version = get_version() | |
tweet = os.getenv("TWEET").format(version=version) | |
client.create_tweet(text=tweet) | |
env: | |
TWEET: | | |
Authx version {version} is out! π | |
https://github.com/yezz123/authx/releases/tag/{version} | |
TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }} | |
TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }} | |
TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} | |
TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} |