Skip to content

Commit 7e389ef

Browse files
erikmdyurug
andauthored
feat(release.yml): Add a (3 jobs)-based GHA using release-please (#434)
* Use var `OPAM_RELEASE` (GitHub PAC) * Use `expect` to workaround the fact that the feature wish ocaml-opam/opam-publish#132 is not yet available. Co-Authored-By: Yann Régis-Gianas <[email protected]> Co-Authored-By: Erik Martin-Dorel <[email protected]>
1 parent dce8f00 commit 7e389ef

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed

.github/workflows/release.yml

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Release
2+
# Credits: workflow inspired from
3+
# https://github.com/grain-lang/binaryen.ml/blob/master/.github/workflows/release.yml
4+
# then slightly adapted, using:
5+
# - https://github.com/googleapis/release-please#readme
6+
# - https://github.com/google-github-actions/release-please-action/blob/main/action.yml
7+
# - https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_run
8+
# - https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts
9+
# - https://github.com/dawidd6/action-download-artifact#readme
10+
# - https://hub.github.com/hub-release.1.html
11+
on:
12+
workflow_run:
13+
workflows: ["Generate static binaries"]
14+
branches: ["master"]
15+
types: ["completed"]
16+
# TODO: dispatch?
17+
18+
jobs:
19+
release-please:
20+
name: Create Release
21+
runs-on: ubuntu-latest
22+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
23+
outputs:
24+
release_created: ${{ steps.release.outputs.release_created }}
25+
upload_url: ${{ steps.release.outputs.upload_url }}
26+
tag_name: ${{ steps.release.outputs.tag_name }}
27+
body: ${{ steps.release.outputs.body }}
28+
steps:
29+
- uses: GoogleCloudPlatform/release-please-action@v2
30+
id: release
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
release-type: ocaml
34+
package-name: learn-ocaml
35+
bump-minor-pre-major: true
36+
37+
add-binaries:
38+
needs: [release-please]
39+
if: ${{ needs.release-please.outputs.release_created }}
40+
name: Add archive and binaries to release
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Check out the repo
44+
# Mandatory step (otherwise, hub raises "fatal: Not a git repository")
45+
uses: actions/checkout@v2
46+
- name: Download workflow artifacts
47+
# cf. https://github.com/actions/download-artifact/issues/3
48+
uses: dawidd6/action-download-artifact@v2
49+
with:
50+
workflow: static-builds.yml
51+
workflow_conclusion: success
52+
commit: ${{ github.sha }}
53+
path: artifacts
54+
- name: Unpack workflow artifacts
55+
run: |
56+
cd artifacts
57+
mkdir -v target
58+
dist=(linux darwin)
59+
artifact() { printf "learn-ocaml-%s-x86_64.tar.gz" "$d"; }
60+
for d in "${dist[@]}"; do
61+
mkdir -v -- "$d"
62+
( cd "$d" && tar xvzf "../$(artifact "$d")/$(artifact "$d")" )
63+
bin=(./learn-ocaml-client ./learn-ocaml-server ./learn-ocaml)
64+
for b in "${bin[@]}"; do
65+
mv -v -- "$d/$b" "target/$b-$d-x86_64"
66+
done
67+
done
68+
- name: Add binaries to release
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
run:
72+
hub release edit $(find artifacts/target -type f -printf "-a %p ") -m "" "${{ needs.release-please.outputs.tag_name }}"
73+
74+
opam-release:
75+
needs: [release-please]
76+
if: ${{ needs.release-please.outputs.release_created }}
77+
name: Publish to opam registry
78+
env:
79+
# Can be changed for debugging
80+
source_repo: "ocaml-sf/learn-ocaml"
81+
opam_repo: "ocaml/opam-repository"
82+
runs-on: ubuntu-latest
83+
steps:
84+
- name: Check out the repo
85+
uses: actions/checkout@v2
86+
- name: Setup bot user
87+
run: |
88+
git config --global user.email "[email protected]"
89+
git config --global user.name "Learn-OCaml Bot"
90+
# Some hacks to make sure opam doesn't pull the repo in a way we can't deal with
91+
- name: Setup opam repository
92+
run: |
93+
mkdir -v -p ~/.opam/plugins/opam-publish/repos/
94+
git clone git://github.com/$opam_repo ~/.opam/plugins/opam-publish/repos/${opam_repo/\//%}
95+
cd ~/.opam/plugins/opam-publish/repos/${opam_repo/\//%}
96+
git remote add user https://${{ secrets.OPAM_RELEASE }}@github.com/proofbot/opam-repository
97+
# Set up our token because opam doesn't support env var tokens
98+
- name: Setup token
99+
run: |
100+
mkdir -p ~/.opam/plugins/opam-publish/
101+
echo -n ${{ secrets.OPAM_RELEASE }} > ~/.opam/plugins/opam-publish/proofbot.token
102+
- name: Generate CHANGES file
103+
env:
104+
CHANGES: ${{ needs.release-please.outputs.body }}
105+
run: |
106+
printf "%s" "$CHANGES" > CHANGES.md
107+
# TODO: Docker-based caching
108+
- name: Setup OCaml
109+
uses: avsm/setup-ocaml@v1
110+
with:
111+
ocaml-version: 4.12.0
112+
- name: Install opam-publish
113+
run: |
114+
opam install -y -j 2 opam-publish
115+
- name: Install expect
116+
run: |
117+
sudo apt-get update -y -q
118+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends expect
119+
- name: Publish to opam
120+
run: |
121+
./scripts/opam-publish.exp "${{ needs.release-please.outputs.tag_name }}" "$opam_repo" "$source_repo"

scripts/opam-publish.exp

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/expect -f
2+
3+
set tag_name [lindex $argv 0]
4+
set opam_repo [lindex $argv 1]
5+
set source_repo [lindex $argv 2]
6+
7+
# This Expect script was generated by autoexpect on Tue Oct 5 17:03:15 2021
8+
# then modified by Erik Martin-Dorel
9+
# Expect and autoexpect were both written by Don Libes, NIST.
10+
#
11+
# Note that autoexpect does not guarantee a working script. It
12+
# necessarily has to guess about certain things. Two reasons a script
13+
# might fail are:
14+
#
15+
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
16+
# etc.) and devices discard or ignore keystrokes that arrive "too
17+
# quickly" after prompts. If you find your new script hanging up at
18+
# one spot, try adding a short sleep just before the previous send.
19+
# Setting "force_conservative" to 1 (see below) makes Expect do this
20+
# automatically - pausing briefly before sending each character. This
21+
# pacifies every program I know of. The -c flag makes the script do
22+
# this in the first place. The -C flag allows you to define a
23+
# character to toggle this mode off and on.
24+
25+
set force_conservative 0 ;# set to 1 to force conservative mode even if
26+
;# script wasn't run conservatively originally
27+
if {$force_conservative} {
28+
set send_slow {1 .1}
29+
proc send {ignore arg} {
30+
sleep .1
31+
exp_send -s -- $arg
32+
}
33+
}
34+
35+
#
36+
# 2) differing output - Some programs produce different output each time
37+
# they run. The "date" command is an obvious example. Another is
38+
# ftp, if it produces throughput statistics at the end of a file
39+
# transfer. If this causes a problem, delete these patterns or replace
40+
# them with wildcards. An alternative is to use the -p flag (for
41+
# "prompt") which makes Expect only look for the last line of output
42+
# (i.e., the prompt). The -P flag allows you to define a character to
43+
# toggle this mode off and on.
44+
#
45+
# Read the man page for more info.
46+
#
47+
# -Don
48+
49+
50+
set timeout -1
51+
spawn bash -c {export GIT_PAGER=cat && opam publish --no-browser --msg-file=CHANGES.md --tag "$1" --repo="$2" "$3"} bash "$tag_name" "$opam_repo" "$source_repo"
52+
match_max 100000
53+
expect -exact "Please confirm the above data. Continue ? \[Y/n\] "
54+
send -- "y"
55+
expect -exact "File a pull-request for this patch ? \[Y/n\] "
56+
send -- "y"
57+
expect eof

0 commit comments

Comments
 (0)