77 schedule :
88 - cron : ' 0 19 * * *'
99jobs :
10+ prepare :
11+ name : Check if the latest ruby commit is already built
12+ runs-on : ubuntu-latest
13+ outputs :
14+ should_build : ${{ steps.check_commit.outputs.result }}
15+ commit : ${{ steps.latest_commit.outputs.commit }}
16+ steps :
17+ - name : Clone ruby
18+ uses : actions/checkout@v3
19+ with :
20+ repository : ruby/ruby
21+ path : ruby
22+ - name : Set latest_commit
23+ id : latest_commit
24+ working-directory : ruby
25+ run : echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
26+
27+ - name : Check if latest commit already built
28+ uses : actions/github-script@v6
29+ id : check_commit
30+ with :
31+ script : |
32+ const latestDevCommit = "${{ steps.latest_commit.outputs.commit }}"
33+ const { owner, repo } = context.repo
34+ let { data: release } = await github.rest.repos.getLatestRelease({ owner, repo })
35+ const latestReleaseCommit = release.body.split('@')[1]
36+ console.log(`Latest release commit: ${latestReleaseCommit}`)
37+ console.log(`Latest ruby commit: ${latestDevCommit}`)
38+ if (latestReleaseCommit === latestDevCommit) {
39+ return 'false'
40+ } else {
41+ return 'true'
42+ }
43+ result-encoding : string
44+
1045 release :
1146 name : Create GitHub Release
47+ needs : [prepare]
48+ if : needs.prepare.outputs.should_build == 'true'
1249 runs-on : ubuntu-latest
1350 outputs :
14- release_id : ${{ steps.create_release.outputs.id }}
15- upload_url : ${{ steps.create_release.outputs.upload_url }}
51+ tag : ${{ steps.tag.outputs.tag }}
1652 steps :
1753 - uses : actions/checkout@v3
1854 with :
@@ -29,33 +65,37 @@ jobs:
2965 fi
3066 echo "tag=$tag" >> $GITHUB_OUTPUT
3167 - name : Create Release
32- id : create_release
33- uses : actions/create-release@v1
3468 env :
35- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
69+ GH_TOKEN : ${{ github.token }}
3670 GH_REPO : ${{ github.repository }}
37- with :
38- tag_name : ${{ steps.tag.outputs.tag }}
39- release_name : ${{ steps.tag.outputs.tag }}
40- draft : true
41- prerelease : false
71+ run : |
72+ tag="${{ steps.tag.outputs.tag }}"
73+ body="ruby/ruby@${{ needs.prepare.outputs.commit }}"
74+ gh release create --draft "$tag" --title "$tag" --notes "$body"
4275
4376 build :
44- needs : [release]
77+ needs : [prepare, release]
4578 strategy :
4679 fail-fast : false
4780 matrix :
4881 os : [ ubuntu-20.04, ubuntu-22.04, macos-11 ]
4982 name : [ head, debug ]
5083 runs-on : ${{ matrix.os }}
5184 steps :
85+ - name : Clone ruby
86+ uses : actions/checkout@v3
87+ with :
88+ repository : ruby/ruby
89+ ref : ${{ needs.prepare.outputs.commit }}
90+
5291 - name : Set platform
5392 id : platform
5493 run : |
5594 platform=${{ matrix.os }}
5695 platform=${platform/macos-*/macos-latest}
5796 echo "platform=$platform" >> $GITHUB_OUTPUT
5897
98+ # Build
5999 - name : apt-get update on Ubuntu
60100 run : sudo apt-get update
61101 if : startsWith(matrix.os, 'ubuntu')
@@ -71,11 +111,6 @@ jobs:
71111 sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
72112 sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
73113
74- - name : Clone Ruby
75- uses : actions/checkout@v3
76- with :
77- repository : ruby/ruby
78-
79114 # ENABLE_PATH_CHECK=0: https://github.com/actions/virtual-environments/issues/267
80115 - name : Set configure flags (head)
81116 run : |
@@ -122,25 +157,21 @@ jobs:
122157 run : ruby -e 'p RbConfig::CONFIG["cppflags"]; def Warning.warn(s); raise s; end; system RbConfig.ruby, "-e", "p :OK"'
123158
124159 - name : Upload Built Ruby
125- uses : actions/upload-release-asset@v1
126160 env :
127- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
128- with :
129- upload_url : ${{ needs.release.outputs.upload_url }}
130- asset_path : ruby-${{ matrix.name }}-${{ steps.platform.outputs.platform }}.tar.gz
131- asset_name : ruby-${{ matrix.name }}-${{ steps.platform.outputs.platform }}.tar.gz
132- asset_content_type : application/gzip
161+ GH_TOKEN : ${{ github.token }}
162+ GH_REPO : ${{ github.repository }}
163+ run : gh release upload "${{ needs.release.outputs.tag }}" "ruby-${{ matrix.name }}-${{ steps.platform.outputs.platform }}.tar.gz"
133164
134- metadata :
165+ publish :
135166 name : Publish Release
136167 needs : [release, build]
137168 runs-on : ubuntu-latest
138169 steps :
139- - uses : eregon/publish-release@v1
170+ - name : Publish Release
140171 env :
141- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
142- with :
143- release_id : ${{ needs.release.outputs.release_id }}
172+ GH_TOKEN : ${{ github.token }}
173+ GH_REPO : ${{ github.repository }}
174+ run : gh release edit " ${{ needs.release.outputs.tag }}" --draft=false
144175 - uses : eregon/keep-last-n-releases@v1
145176 env :
146177 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments