Browse Source

ref: upgrade actions/cache to v3.0.8 (#38096)

anthony sottile 2 years ago
parent
commit
7734b27d47

+ 2 - 2
.github/actions/setup-volta/action.yml

@@ -10,7 +10,7 @@ runs:
 
     - name: cache volta+node+yarn
       id: cache
-      uses: actions/cache@9df7d7c016256c51d661e5d26a8632ccd0581680  # v3.0.7
+      uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8  # v3.0.8
       with:
         path: ${{ steps.vars.outputs.volta-dir }}
         key: ${{ steps.vars.outputs.cache-key }}
@@ -26,7 +26,7 @@ runs:
       run: python3 -uS ${{ github.action_path }}/bin/setup-volta yarn-cache-dir
 
     - name: cache yarn
-      uses: actions/cache@9df7d7c016256c51d661e5d26a8632ccd0581680  # v3.0.7
+      uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8  # v3.0.8
       with:
         path: ${{ steps.yarn.outputs.cache-dir }}
         key: ${{ steps.vars.outputs.cache-key }}-${{ hashFiles('**/yarn.lock') }}

+ 6 - 2
.github/workflows/acceptance.yml

@@ -13,6 +13,10 @@ on:
       - releases/**
   pull_request:
 
+# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
+env:
+  SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
+
 jobs:
   files-changed:
     name: detect what files changed
@@ -133,7 +137,7 @@ jobs:
         run: echo "::set-output name=webpack-path::.webpack_cache"
 
       - name: webpack cache
-        uses: actions/cache@9df7d7c016256c51d661e5d26a8632ccd0581680  # v3.0.7
+        uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8  # v3.0.8
         with:
           path: ${{ steps.config.outputs.webpack-path }}
           key: ${{ runner.os }}-v2-webpack-cache-${{ hashFiles('webpack.config.ts') }}
@@ -211,7 +215,7 @@ jobs:
           chartcuterie: true
 
       - name: yarn cache
-        uses: actions/cache@9df7d7c016256c51d661e5d26a8632ccd0581680  # v3.0.7
+        uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8  # v3.0.8
         with:
           path: ${{ steps.setup.outputs.yarn-cache-dir }}
           key: ${{ runner.os }}-v2-yarn-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock') }}

+ 5 - 1
.github/workflows/backend.yml

@@ -6,6 +6,10 @@ on:
       - master
   pull_request:
 
+# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
+env:
+  SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
+
 jobs:
   files-changed:
     name: detect what files changed
@@ -243,7 +247,7 @@ jobs:
           cache: pip
           cache-dependency-path: requirements-dev-only-frozen.txt
 
-      - uses: actions/cache@9df7d7c016256c51d661e5d26a8632ccd0581680  # v3.0.7
+      - uses: actions/cache@56046cbc4743437ac40542086317b1561d7705f8  # v3.0.8
         with:
           path: ~/.cache/pre-commit
           key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}

+ 4 - 0
.github/workflows/development-environment.yml

@@ -15,6 +15,10 @@ on:
       - 'src/sentry/runner/commands/devservices.py'
       - 'bin/load-mocks'
 
+# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
+env:
+  SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
+
 jobs:
   # This workflow is optimized to test the dev env with dev services as fast as possible
   # The bootstrap workflow (see last workflow) tests the experience of first time engineers

+ 4 - 0
.github/workflows/frontend.yml

@@ -6,6 +6,10 @@ on:
       - master
   pull_request:
 
+# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
+env:
+  SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
+
 jobs:
   files-changed:
     name: detect what files changed

+ 4 - 0
.github/workflows/openapi-diff.yml

@@ -2,6 +2,10 @@ name: openapi-diff
 on:
   pull_request:
 
+# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
+env:
+  SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
+
 jobs:
   check-diff:
     name: build api

+ 4 - 0
.github/workflows/openapi.yml

@@ -4,6 +4,10 @@ on:
     branches:
       - master
 
+# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
+env:
+  SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
+
 jobs:
   build_and_deref_json:
     runs-on: ubuntu-20.04

+ 5 - 0
.github/workflows/sync-labels.yml

@@ -8,6 +8,11 @@ on:
       - master
     paths:
       - .github/labels.yml
+
+# hack for https://github.com/actions/cache/issues/810#issuecomment-1222550359
+env:
+  SEGMENT_DOWNLOAD_TIMEOUT_MIN: 3
+
 jobs:
   sync:
     name: syncs repository labels

+ 121 - 0
tests/tools/test_bump_action.py

@@ -0,0 +1,121 @@
+import subprocess
+from unittest import mock
+
+import pytest
+
+from tools.bump_action import main
+
+
+@pytest.fixture
+def workflow_and_action(tmp_path):
+    base = tmp_path.joinpath("root")
+
+    base.joinpath(".github/workflows").mkdir(parents=True)
+    workflow = base.joinpath(".github/workflows/main.yml")
+
+    base.joinpath(".github/actions/myaction").mkdir(parents=True)
+    action = base.joinpath(".github/actions/myaction/action.yml")
+
+    yield base, workflow, action
+
+
+def test_main_noop(workflow_and_action, capsys):
+    base, workflow, action = workflow_and_action
+
+    workflow_src = """\
+name: main
+on:
+  push:
+jobs:
+  main:
+    runs-on: ubuntu-latest
+    steps:
+    - run: echo hi
+"""
+
+    action_src = """\
+name: my-action
+inputs:
+  arg:
+    required: true
+
+runs:
+  using: composite
+  steps:
+  - run: echo hi
+    shell: bash
+"""
+
+    workflow.write_text(workflow_src)
+    action.write_text(action_src)
+
+    assert main(("actions/whatever", "v1.2.3", f"--base-dir={base}")) == 0
+    out, err = capsys.readouterr()
+    assert out == err == ""
+
+
+def test_main_upgrades_action(workflow_and_action, capsys):
+    base, workflow, action = workflow_and_action
+
+    workflow_src = """\
+name: main
+on:
+  push:
+jobs:
+  main:
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/whatever@v0.1.2
+"""
+    workflow_expected = """\
+name: main
+on:
+  push:
+jobs:
+  main:
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/whatever@v1.2.3
+"""
+
+    action_src = """\
+name: my-action
+inputs:
+  arg:
+    required: true
+
+runs:
+  using: composite
+  steps:
+  - uses: actions/whatever@v0.1.2
+"""
+    action_expected = """\
+name: my-action
+inputs:
+  arg:
+    required: true
+
+runs:
+  using: composite
+  steps:
+  - uses: actions/whatever@v1.2.3
+"""
+
+    workflow.write_text(workflow_src)
+    action.write_text(action_src)
+
+    with mock.patch.object(subprocess, "call", return_value=123):
+        assert main(("actions/whatever", "v1.2.3", f"--base-dir={base}")) == 123
+
+    out, err = capsys.readouterr()
+    assert (
+        out
+        == f"""\
+{workflow} upgrading actions/whatever...
+{action} upgrading actions/whatever...
+freezing...
+"""
+    )
+
+    assert workflow.read_text() == workflow_expected
+    assert action.read_text() == action_expected

+ 47 - 0
tools/bump_action.py

@@ -0,0 +1,47 @@
+from __future__ import annotations
+
+import argparse
+import glob
+import os.path
+import re
+import subprocess
+import sys
+from typing import Sequence
+
+
+def main(argv: Sequence[str] | None = None) -> int:
+    parser = argparse.ArgumentParser()
+    parser.add_argument("action")
+    parser.add_argument("version")
+    parser.add_argument("--base-dir", default=".")
+    args = parser.parse_args(argv)
+
+    reg = re.compile(f"(?<=uses: {re.escape(args.action)}@).*$", re.M)
+
+    filenames = [
+        filename
+        for yml_glob in (".github/workflows/*.yml", ".github/actions/*/*.yml")
+        for filename in glob.glob(os.path.join(args.base_dir, yml_glob))
+    ]
+
+    changed = []
+    for filename in filenames:
+        with open(filename) as f:
+            original_contents = f.read()
+            contents = reg.sub(args.version, original_contents)
+
+        if contents != original_contents:
+            print(f"{filename} upgrading {args.action}...")
+            changed.append(filename)
+            with open(filename, "w") as f:
+                f.write(contents)
+
+    if changed:
+        print("freezing...")
+        return subprocess.call((sys.executable, "-m", "tools.pin_github_action", *changed))
+    else:
+        return 0
+
+
+if __name__ == "__main__":
+    raise SystemExit(main())