From c6066cae5fb03a03ca448fd2ef435e1567777d7a Mon Sep 17 00:00:00 2001 From: bensteinberg Date: Wed, 1 Nov 2023 13:40:59 -0400 Subject: [PATCH] Update deprecated set-output command --- test_update_tags.py | 19 +++++++++++++------ update_tags.py | 4 +++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/test_update_tags.py b/test_update_tags.py index b473c6a..606bbcd 100644 --- a/test_update_tags.py +++ b/test_update_tags.py @@ -5,6 +5,7 @@ from textwrap import dedent import pytest +import os import update_tags @@ -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" @@ -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] diff --git a/update_tags.py b/update_tags.py index 2d5d9bc..429031e 100644 --- a/update_tags.py +++ b/update_tags.py @@ -2,6 +2,7 @@ import hashlib import requests from pathlib import Path +import os import yaml @@ -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():