GitHub Actionsのワークフローで変数を利用する

取り敢えず各ジョブの中で使うやつ

今まで使っていた::set-outputは2023-05-31に廃止される予定なので置き換える必要があります。

GitHub Actions: Deprecating save-state and set-output commands

サンプルコード

  • 設定方法:echo "<KEY>=<VALUE>" >> "$GITHUB_OUTPUT"
  • 参照方法:steps.<ID>.outputs.{KEY}
name: variable example
on:
  workflow_dispatch:
jobs:
  ubuntu-testing:
    runs-on: ubuntu-latest
    steps:
      - id: example
        run: echo "value=hoge" >> "$GITHUB_OUTPUT"
      - name: disp
        run: echo ${{ steps.example.outputs.value }}

React + TS + Jestでカスタムフックのテストをする

フックを単体でテストするケースを想定。

このパターンはコンポーネントからフックを切り離しているケースで有用。手法としては@testing-library/react-hooksのrenderHook()を使う。

例

カスタムフック

export const useUserForm = () => {
  const [username, setUsername] = useState('');
  const [password, setPassword] = useState('');

  const onChangeUserName = (ev: string) => {
    setUsername(ev);
  };
  const onChangePassword = (ev: string) => {
    setPassword(ev);
  };

  return {
    username,
    password,
    onChangeUserName,
    onChangePassword,
  };
};

テストコード

it('onChangeUserName で username が設定されること', () => {
  // `renderHook` で Hook をレンダリング
  const { result } = renderHook(() => useUserForm());
  // `act()` で Hook のイベントを叩く
  act(() => result.current.onChangeUserName('foo'));
  // 結果を見る
  expect(result.current.username).toBe('foo');
});

Rx.NETでWindows Formを操作するサンプル

  1. System.ReactiveをNuGetから入れる
  2. this.ticker= Observable.Interval(new TimeSpan(0, 0, 15));でObserverを作る
this.ticker.Subscribe(
    (item) => {
        // 任意のコントロールを操作する例
        // this.Invokeでコントロールを操作するメソッドを呼び出すと実現できる
        this.Invoke(
            (MethodInvoker)(delegate () {
                // ここに処理
            })
        );
    }
);

どうでもいいけどRx.NETってちゃんとしたリファレンスなくね?

Windowsで踏み台を使ったSSH接続の設定方法

  • %HOMEPATH%\.ssh\configに以下のように設定すると踏み台サーバーを経由したSSH接続が可能
    • 設定は踏み台には証明書認証があるが、宛先にはないケースを想定
  • ssh target-host.devとすると踏み台経由でアクセス可能
    • ProxyCommandではssh.exeをフルパスで記述する必要がある
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host proxy.ssh-host.dev
  HostName proxy.ssh-host.dev
  User foo
  IdentityFile C:\Users\user-name\.ssh\id_rsa
  ForwardAgent yes
Host target-host.dev
  Hostname target-host.dev
  User bar
  ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -l %r -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null proxy.ssh-host.dev -W %h:%p

VSCodeでXdebugからの余計な例外を無視する

余計な例外を投げてくるのが面倒なのでそれを無視できるように

確認環境

Env Ver
PHP 7.1.3
Xdebug 2.9.4
VSCode 1.48.0

内容

"ignore"セクションを追加してそこに書いたファイルから出た例外は無視される

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9001,
            "ignore": [
                "**/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php"
            ]
        }
    ]
}