This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# checkoutその他は省略 | |
- run: sbt compileなどの他のタスク色々 writeExternalDependencies | |
- name: upload dependencies.txt | |
if: github.event_name == 'push' | |
run: | | |
# いい感じにuploadとdownloadできれば、 | |
# github actionsのartifactでもなんでも良い。 | |
# 最近某所ではS3の方が便利というか楽なので、それ使ったりもしているので、その場合の例 | |
aws s3 cp target/dependencies.txt s3://適当なURI/${{github.ref_name}}/dependencies.txt | |
- id: get_previous_dependencies | |
if: github.event_name == 'pull_request' | |
run: | | |
# TODO 存在確認ってもう少し綺麗に書けないんか? | |
if [[ $(aws s3 ls s3://適当なURI/${{github.base_ref}}/ | grep dependencies.txt) ]] ; then | |
aws s3 cp s3://適当なURI/${{github.base_ref}}/dependencies.txt target/dependencies-previous.txt | |
diff target/dependencies-previous.txt target/dependencies.txt > target/dependencies.diff || true | |
echo 'value=true' >> $GITHUB_OUTPUT | |
else | |
# 初回や、特定のbranch以外ではあり得るのでエラーにはしない | |
echo "${{github.base_ref}} のdependencies.txtが存在しない" | |
echo 'value=false' >> $GITHUB_OUTPUT | |
fi | |
- uses: actions/github-script@v6 | |
if: (github.event_name == 'pull_request') && (steps.get_previous_dependencies.outputs.value == 'true') | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const diff = fs.readFileSync("target/dependencies.diff").toString(); | |
if (diff.length == 0) { | |
// diffがないこと自体をbotにpull req commentさせてもいいかも。 | |
console.log("dependenciesのdiffは無し"); | |
} else { | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: "dependencies diff\n\n```diff\n" + diff + "\n```" | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.Using | |
import java.io.FileWriter | |
TaskKey[Unit]("writeExternalDependencies", "依存ライブラリ一覧をファイルに出力") := { | |
val s = state.value | |
val extracted = Project.extract(s) | |
// coursierのcacheディレクトリの共通部分は省略したいため、pathをここでsplitして、そこから先のみ出力する | |
val coursierMavenCentralDir = "repo1.maven.org/maven2/" | |
val values = extracted.structure.allProjectRefs | |
.filter(x => /* 好みによって?、最終的にデプロイされる単位でfilterなどする */ ) | |
.sortBy(_.project) // 必ず同じ出力になるようにsort | |
.map { p => | |
p.project -> extracted | |
.runTask( | |
// ひとまずmain側のみ | |
p / Compile / externalDependencyClasspath, | |
s | |
) | |
._2 | |
.map(_.data.getCanonicalPath.split(coursierMavenCentralDir).last) | |
.sorted // 必ず同じ出力になるようにsort | |
} | |
assert(values.nonEmpty) | |
val log = streams.value.log | |
Using.resource(new FileWriter((LocalRootProject / target).value / "dependencies.txt")) { writer => | |
values.foreach { | |
case (project, dependencies) => | |
assert(dependencies.nonEmpty, s"${project}の依存一覧取得失敗!?") | |
log.info(s"write ${project} dependencies ${dependencies.size}") | |
dependencies.foreach { x => | |
// diffコマンドで差分を出す時に、project名がすぐわかるように、 | |
// 冗長だが全ての行にsub project名自体を直接埋め込む | |
writer.write(project) | |
writer.write(": ") | |
writer.write(x) | |
writer.write("\n") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment