Skip to content

Commit

Permalink
Update deprecated set-output command
Browse files Browse the repository at this point in the history
  • Loading branch information
bensteinberg committed Nov 1, 2023
1 parent a1fcdef commit c6066ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 13 additions & 6 deletions test_update_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from textwrap import dedent

import pytest
import os

import update_tags

Expand Down Expand Up @@ -48,17 +49,17 @@ def test_main(test_files, monkeypatch):
monkeypatch.setattr(update_tags, 'remote_tag_exists', lambda *args: False)

# first run detects changes to toplevel and subdir
out = update_tags.main(compose_path)
assert out == f"::set-output name=services-to-rebuild::toplevel subdir"
update_tags.main(compose_path)
assert github_output() == "services-to-rebuild=toplevel subdir"

# no update the second time
out = update_tags.main(compose_path)
assert out == f"::set-output name=services-to-rebuild::"
update_tags.main(compose_path)
assert github_output() == "services-to-rebuild="

# 'push' action checks rebuild for all tags if there are any
# changes
out = update_tags.main(compose_path, action='push')
assert out == f"::set-output name=services-to-rebuild::toplevel subdir"
update_tags.main(compose_path, action='push')
assert github_output() == "services-to-rebuild=toplevel subdir"

# check hash values -- hashes are: build config, Dockerfile contents, x-hash-paths contents
toplevel_hash = "bd018100e5b1c9159130decc1fa8884c"
Expand Down Expand Up @@ -114,3 +115,9 @@ def main_patch(docker_compose_path, action):
monkeypatch.setattr("sys.argv", ["foo", "-a", "push", "-f", "foo/docker-compose.yml"])
monkeypatch.setattr(update_tags, 'main', main_patch)
update_tags.run_from_command_line()


def github_output():
return Path(
os.environ['GITHUB_OUTPUT']
).read_text().rstrip().split('\n')[-1]
4 changes: 3 additions & 1 deletion update_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib
import requests
from pathlib import Path
import os

import yaml

Expand Down Expand Up @@ -116,7 +117,8 @@ def main(docker_compose_path='docker-compose.yml', action='load'):

# string format to set steps.get-tag.outputs.rebuild_services if printed:
print(f"Returning services-to-rebuild: {to_rebuild}")
return f"::set-output name=services-to-rebuild::{' '.join(to_rebuild)}"
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f"services-to-rebuild={' '.join(to_rebuild)}", file=fh)


def run_from_command_line():
Expand Down

0 comments on commit c6066ca

Please sign in to comment.