|
| 1 | +# Demonstrate how to properly `apt-get install inn2` in a GitHub Action. |
| 2 | +# Configure the inn2 instance so that other code can test interactions with the inn2 server. |
| 3 | + |
| 4 | +name: InterNetNews2 |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [ main ] |
| 8 | + pull_request: |
| 9 | + branches: [ main ] |
| 10 | + workflow_dispatch: |
| 11 | +jobs: |
| 12 | + inn2: |
| 13 | + runs-on: ubuntu-24.04 |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + - name: cat "localhost.localdomain" > /etc/hostname |
| 17 | + run: | |
| 18 | + echo "localhost.localdomain" > hostname |
| 19 | + sudo mv hostname /etc/ |
| 20 | + cat /etc/hostname |
| 21 | + # The next commands usually pass but not always!!! |
| 22 | + - run: | |
| 23 | + sudo apt-get update -qq |
| 24 | + sudo apt-get install --yes inn2 |
| 25 | + # - run: cat /etc/news/inn.conf # Useful for debugging |
| 26 | + - run: systemctl status inn2 |
| 27 | + |
| 28 | + - uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: 3.12 # nntplib was removed from the Standard Library in Python 3.13. |
| 31 | + |
| 32 | + - name: nntplib_demo |
| 33 | + shell: python |
| 34 | + run: | |
| 35 | + import nntplib # Removed from the Standard Library in Python 3.13. |
| 36 | + import pathlib |
| 37 | + with nntplib.NNTP("localhost", readermode=True) as nntp_server: |
| 38 | + print(f"{nntp_server = }") |
| 39 | + # print(f"{nntp_server.starttls() = }") # nntplib.NNTPTemporaryError: 401 MODE-READER |
| 40 | + print(f"{nntp_server.nntp_version = }") |
| 41 | + print(f"{nntp_server.nntp_implementation = }") |
| 42 | + print(f"{nntp_server.getwelcome() = }") |
| 43 | + print(f"{nntp_server.getcapabilities() = }") |
| 44 | + print(f"{nntp_server.list() = }") |
| 45 | + print("News group list:") |
| 46 | + print("\n".join( |
| 47 | + f"{i}. {group_info.group}" for i, group_info in enumerate(nntp_server.list()[1], 1) |
| 48 | + )) |
| 49 | + # Ensure the 'local.test' group has no articles. |
| 50 | + resp, count, first, last, name = nntp_server.group('local.test') |
| 51 | + print(f"Group '{name}' has {count} articles, range {first} to {last}.") |
| 52 | + # Post an article to the 'local.test' group. |
| 53 | + msg = pathlib.Path("contrib/inn_article_001.txt").read_text() |
| 54 | + # print(f"{msg = }") |
| 55 | + response = nntp_server.post(msg.encode("utf-8")) |
| 56 | + print(f"{response = }") |
| 57 | + # Verify that the article is there. |
| 58 | + resp, count, first, last, name = nntp_server.group('local.test') |
| 59 | + print(f"Group '{name}' has {count} articles, range {first} to {last}.") |
| 60 | + # Read the article. |
| 61 | + stat = nntp_server.stat() # last() and next() both fail |
| 62 | + # print(f"{stat = }") |
| 63 | + article = nntp_server.article(stat[2]) |
| 64 | + print(f"{article = }") |
| 65 | + # Print the lines of the article |
| 66 | + print("\n".join(line.decode("utf-8") for line in article[1].lines)) |
| 67 | + # Print the overview information |
| 68 | + resp, count, first, last, name = nntp_server.group('local.test') |
| 69 | + # print(resp, count, first, last, name) |
| 70 | + resp, overviews = nntp_server.over((first, last)) |
| 71 | + for id, over in overviews: |
| 72 | + print(id, nntplib.decode_header(over['subject'])) |
0 commit comments