Closed sinkcup closed 3 years ago
打算做 PHP 多版本、多框架 的 CI 验证。
多版本:按照 PHP 官方支持的版本列表——7.3、7.4、8.0 是正规做法,不应该支持废弃(漏洞无人维护)的 5.6 版本。
https://www.php.net/supported-versions.php
但 sdk 文档说支持 5.6,所以首先进行验证:发现其实已经不支持 5.6 了,挺好,省事了!
那就意味着,首先要修正 composer.json
的依赖版本。目测是 PHP 7 https://www.php.net/manual/zh/migration70.new-features.php
按照官方规范,应该直接提高到 7.3,如果有 7.0-7.2 的老用户,安装时会匹配老 sdk,也会安装成功。
除非一个场景:sdk 又新增了功能,而 7.0 老用户安装的永远是老 sdk,但可能性不大,如果一个人还在用 PHP 7.0,线上漏洞都不管了,怎么会用到 sdk 新功能呢?
发现 guzzle7 就是升级了版本依赖,合并过来就可以了。
https://github.com/tencentyun/cos-php-sdk-v5/compare/guzzle7
写了 GitHub Actions,在我 fork 的仓库里设置了环境变量。
以为应该没啥问题,就直接提交,在 CI 里跑单元测试,结果报错:https://github.com/sinkcup/cos-php-sdk-v5/runs/3351597587?check_suite_focus=true
Call to undefined function GuzzleHttp\Psr7\stream_for()
于是锁定 psr7 < 2.0,函数没问题了,本地单元测试失败,CI 里也是:https://github.com/sinkcup/cos-php-sdk-v5/runs/3351860386?check_suite_focus=true
There were 9 failures:
1) Qcloud\Cos\Tests\COSTest::testInvalidRegionBucket
Failed asserting that true is false.
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:122
2) Qcloud\Cos\Tests\COSTest::testPutBucketAclByBody
Failed asserting that true is false.
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:462
3) Qcloud\Cos\Tests\COSTest::testPutBucketAclByBodyToAnyone
Failed asserting that true is false.
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:495
4) Qcloud\Cos\Tests\COSTest::testPutBucket2
Failed asserting that true is false.
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:987
5) Qcloud\Cos\Tests\COSTest::testPutObjectMeta
Array (...) does not match expected type "NULL".
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:1202
6) Qcloud\Cos\Tests\COSTest::testPutObjectACL
Failed asserting that true is false.
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:1582
7) Qcloud\Cos\Tests\COSTest::testGetObjectACL
Failed asserting that true is false.
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:1619
8) Qcloud\Cos\Tests\COSTest::testPutObjectAclByBody
Failed asserting that true is false.
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:1831
9) Qcloud\Cos\Tests\COSTest::testPutObjectAclByBodyToAnyone
Failed asserting that true is false.
/Volumes/Code/sinkcup/cos-php-sdk-v5/src/Qcloud/Cos/Tests/COSTest.php:1867
ERRORS!
Tests: 79, Assertions: 104, Errors: 6, Failures: 9.
切换到当年成功的代码:https://travis-ci.com/github/tencentyun/cos-php-sdk-v5/builds/212180645
使用 PHP 5.6 本地运行也不对:
There were 11 failures:
1) Qcloud\Cos\Tests\COSTest::testPutBucketAclByBody
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:452
2) Qcloud\Cos\Tests\COSTest::testPutBucketAclByBodyToAnyone
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:485
3) Qcloud\Cos\Tests\COSTest::testUploadLargeObjectMeta
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1119
4) Qcloud\Cos\Tests\COSTest::testUploadComplexObject
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1162
5) Qcloud\Cos\Tests\COSTest::testUploadLargeObject
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1184
6) Qcloud\Cos\Tests\COSTest::testResumeUpload
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1220
7) Qcloud\Cos\Tests\COSTest::testCopyLargeObject
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1396
8) Qcloud\Cos\Tests\COSTest::testPutObjectACL
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1431
9) Qcloud\Cos\Tests\COSTest::testGetObjectACL
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1468
10) Qcloud\Cos\Tests\COSTest::testPutObjectAclByBody
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1680
11) Qcloud\Cos\Tests\COSTest::testPutObjectAclByBodyToAnyone
Failed asserting that true is false.
/root/src/Qcloud/Cos/Tests/COSTest.php:1716
FAILURES!
Tests: 72, Assertions: 98, Failures: 11.
同事提出一个问题:用户一般来说应该不太会去用test,所以也没办法通过5.6跑不过test推出目前用户的php版本分布。
仔细一看,的确是,test 代码移除类型判断,就可以跑了,src 没问题。
参考各家的 php sdk 版本要求:
尝试同时支持 PHP 5.6-8.0,发现有困难:
如果 test 写成 PHP 5.6 的写法,在 PHP 7+ 里 phpunit 就会报错:setUp 类型不符。
有几个办法:
为什么 src 是 PHP 5.6,而 test 是 PHP 7+?
预计是因为:大家本地开发是 PHP 7+,需要跑 phpunit。
看了一下workflow的报错,检查后发现部分报错是签名不合法,部分是bucketName问题,还有一个error在排查中,我看看test用例
那个bucket名非法,我在我自己的分支上试一下,我看看action咋用的:smile:
看了一下workflow的报错,检查后发现部分报错是签名不合法,部分是bucketName问题,还有一个error在排查中,我看看test用例
我看以前测试成功的 ci 里面是 https://app.travis-ci.com/github/tencentyun/cos-php-sdk-v5
export COS_BUCKET=cos-php-v5-ut-1251668577
我在 GitHub actions 用的 bucket 名字也是这种格式,英文小写、连字符,按说没问题啊。@tuuna
我看到的这个名字怎么有点奇怪🤔难道是test定义有问题?
哦哦,我对着error和failure看
之前的 CI 已不能正常运行,打算迁移到 GitHub Actions
https://travis-ci.com/github/tencentyun/cos-php-sdk-v5