Skip to content

Commit

Permalink
ci(*.yml): Move opam-publish in a separate workflow to enable testing
Browse files Browse the repository at this point in the history
* Follow https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow
* Use `opam-publish>=2.3.0` that offers a new flag `--no-confirmation`
  • Loading branch information
erikmd committed Nov 2, 2023
1 parent 9176975 commit e3880ee
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 104 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/opam-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: OPAM Publish
# See also release.yml
# and https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow
on:
workflow_call:
inputs:
release:
type: string
# not boolean
# see also https://github.com/actions/runner/issues/1483#issuecomment-1372133232
required: false
default: "false"
tag_name:
type: string
required: true
default: "v0.1.0"
body:
type: string
required: true
default: "## 0.1.0"
secrets:
OPAM_RELEASE:
required: true
# = proofbot.token with scopes repo,workflow

jobs:
opam-release:
name: Publish to opam registry
env:
# Note: Update if need be
source_repo: "ocaml-sf/learn-ocaml"
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Prepare target package repository
id: prep
run: |
# Test inputs.release
if [ "${{ inputs.release }}" = 'true' ]; then
echo "opam_repo=ocaml/opam-repository" >> "$GITHUB_OUTPUT"
echo "release mode: target ocaml/opam-repository"
else
# Note: Update if need be
echo "opam_repo=erikmd/opam-repository" >> "$GITHUB_OUTPUT"
echo "dry-run mode: target erikmd/opam-repository"
fi
- name: Setup bot user
run: |
# Note: Update if need be
git config --global user.email "37002148+proofbot@users.noreply.github.com"
git config --global user.name "Learn-OCaml Bot"
# Some hacks to make sure opam doesn't pull the repo in a way we can't deal with
- name: Setup opam repository and token
env:
var_opam_repo: ${{ steps.prep.outputs.opam_repo }}
run: |
mkdir -v -p ~/.opam/plugins/opam-publish/repos/
git clone https://github.com/$var_opam_repo ~/.opam/plugins/opam-publish/repos/${var_opam_repo/\//%}
cd ~/.opam/plugins/opam-publish/repos/${var_opam_repo/\//%}
git remote add user https://github.com/proofbot/opam-repository
git config --global credential.helper 'store --file ~/.git-credentials'
# See also https://stackoverflow.com/a/74841589/9164010
printf "host=github.com\nprotocol=https\nusername=proofbot\npassword=${{ secrets.OPAM_RELEASE }}" | git credential-store store
echo -n ${{ secrets.OPAM_RELEASE }} > ~/.opam/plugins/opam-publish/proofbot.token
- name: Generate CHANGES file
env:
CHANGES: ${{ inputs.body }}
run: |
printf "%s" "$CHANGES" > CHANGES.md
# TODO: Docker-based caching
- name: Setup OCaml
uses: avsm/setup-ocaml@v1
# TODO: Keep up-to-date!
with:
ocaml-version: 4.12.0
- name: Install opam-publish
run: |
opam install -y -j 2 "opam-publish>=2.3.0"
- name: Publish to opam
env:
var_opam_repo: ${{ steps.prep.outputs.opam_repo }}
run: |
export GIT_PAGER=cat
opam publish --no-browser --no-confirmation --msg-file=CHANGES.md --tag="${{ inputs.tag_name }}" --repo="$var_opam_repo" "$source_repo"
59 changes: 12 additions & 47 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
release_created: ${{ steps.release.outputs.release_created }}
upload_url: ${{ steps.release.outputs.upload_url }}
tag_name: ${{ steps.release.outputs.tag_name }}
body: ${{ steps.release.outputs.body }}
body: |
Cc @erikmd @yurug @AltGr
${{ steps.release.outputs.body }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
Expand Down Expand Up @@ -73,54 +76,16 @@ jobs:
run:
hub release edit $(find artifacts/target -type f -printf "-a %p ") -m "" "${{ needs.release-please.outputs.tag_name }}"

opam-release:
call-opam-publish:
needs: [release-please]
if: ${{ needs.release-please.outputs.release_created }}
name: Publish to opam registry
env:
# Can be changed for debugging
source_repo: "ocaml-sf/learn-ocaml"
opam_repo: "ocaml/opam-repository"
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Setup bot user
run: |
git config --global user.email "37002148+proofbot@users.noreply.github.com"
git config --global user.name "Learn-OCaml Bot"
# Some hacks to make sure opam doesn't pull the repo in a way we can't deal with
- name: Setup opam repository
run: |
mkdir -v -p ~/.opam/plugins/opam-publish/repos/
git clone https://github.com/$opam_repo ~/.opam/plugins/opam-publish/repos/${opam_repo/\//%}
cd ~/.opam/plugins/opam-publish/repos/${opam_repo/\//%}
git remote add user https://${{ secrets.OPAM_RELEASE }}@github.com/proofbot/opam-repository
# Set up our token because opam doesn't support env var tokens
- name: Setup token
run: |
mkdir -p ~/.opam/plugins/opam-publish/
echo -n ${{ secrets.OPAM_RELEASE }} > ~/.opam/plugins/opam-publish/proofbot.token
- name: Generate CHANGES file
env:
CHANGES: ${{ needs.release-please.outputs.body }}
run: |
printf "%s" "$CHANGES" > CHANGES.md
# TODO: Docker-based caching
- name: Setup OCaml
uses: avsm/setup-ocaml@v1
with:
ocaml-version: 4.12.0
- name: Install opam-publish
run: |
opam install -y -j 2 opam-publish
- name: Install expect
run: |
sudo apt-get update -y -q
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends expect
- name: Publish to opam
run: |
./scripts/opam-publish.exp "${{ needs.release-please.outputs.tag_name }}" "$opam_repo" "$source_repo"
uses: ./.github/workflows/opam-publish.yml
with:
release: "true"
tag_name: ${{ needs.release-please.outputs.tag_name }}
body: ${{ needs.release-please.outputs.body }}
secrets:
OPAM_RELEASE: ${{ secrets.OPAM_RELEASE }}

# Note: you may want to update the jobs below and deploy-master.yml at once
push_server:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/test-opam-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test OPAM Publish
# See also release.yml
# and https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow
on:
# pull_request:
# branches:
# - "master"
push:
branches:
- "**-gha"
- "preflight"
# for testing (= PR base branch)
# for prod, see workflow Release

jobs:
call-opam-publish:
uses: ./.github/workflows/opam-publish.yml
with:
# release: "false" # by default
tag_name: "v0.15.0"
body: |
Cc @erikmd
## [0.15.0](https://github.com/ocaml-sf/learn-ocaml/compare/v0.14.1...v0.15.0) (2023-08-23)
### Features
* **partition-view:** Add a selector to show (tokens, nicks, or anon IDs) (`#540`) ([58b3644](https://github.com/ocaml-sf/learn-ocaml/commit/58b3644a6d5a3f43cf8d7cb21ebbe40b588f176f)), closes `#528`
* etc.
secrets:
OPAM_RELEASE: ${{ secrets.OPAM_RELEASE }}
57 changes: 0 additions & 57 deletions scripts/opam-publish.exp

This file was deleted.

0 comments on commit e3880ee

Please sign in to comment.