Skip to content

Commit 051eecf

Browse files
committed
Add GitHub Actions workflow for updating access-mopper in Analysis3 Conda environment
1 parent 0b13488 commit 051eecf

1 file changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Update ACCESS-MOPPeR on Analysis3 Conda Environment
2+
# This workflow updates the `access-mopper` package version in the Analysis3 conda environment
3+
# whenever a new release of `access-mopper` is published.
4+
5+
on:
6+
release:
7+
types: ['released', 'prereleased']
8+
workflow_dispatch:
9+
10+
jobs:
11+
bump-env-in-repo-b:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
env:
16+
ORG: ACCESS-NRI
17+
TARGET_REPO: ACCESS-Analysis-Conda
18+
TARGET_BRANCH: main
19+
FILE_PATH: environments/analysis3/environment.yml
20+
PACKAGE: access-mopper
21+
CHANNEL: accessnri
22+
# Derive version from the release tag (e.g. v2.3.0a4 -> 2.3.0a4).
23+
RELEASE_TAG: ${{ github.event.release.tag_name }}
24+
GH_TOKEN: ${{ secrets.GH_ANALYSIS3_DEPLOY }}
25+
26+
steps:
27+
- name: Derive version string
28+
id: ver
29+
run: |
30+
tag="${RELEASE_TAG}"
31+
ver="${tag#v}"
32+
echo "version=$ver" >> $GITHUB_OUTPUT
33+
34+
- name: Install tooling (jq, yq, gh)
35+
run: |
36+
sudo apt-get update -y
37+
sudo apt-get install -y jq
38+
curl -sSL https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 -o yq
39+
sudo install -m 0755 yq /usr/local/bin/yq
40+
type -p gh >/dev/null || (curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
41+
| sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
42+
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
43+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
44+
| sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
45+
sudo apt-get update && sudo apt-get install -y gh)
46+
47+
- name: Wait for conda package to appear in channel
48+
env:
49+
VERSION: ${{ steps.ver.outputs.version }}
50+
run: |
51+
echo "Waiting for ${CHANNEL}::${PACKAGE}==${VERSION} to appear…"
52+
# Up to 30 minutes, check every 60s. Adjust if your CD pipeline needs longer.
53+
for i in $(seq 1 30); do
54+
# Query Anaconda API for package files in the channel
55+
if curl -fsSL "https://api.anaconda.org/package/${CHANNEL}/${PACKAGE}" | \
56+
jq -e --arg v "$VERSION" '.files[] | select(.version == $v) | .version' >/dev/null; then
57+
echo "Found ${PACKAGE} ${VERSION} in channel ${CHANNEL}."
58+
exit 0
59+
fi
60+
echo "Not yet available. Retry $i/30…"
61+
sleep 60
62+
done
63+
echo "Timed out waiting for ${CHANNEL}::${PACKAGE}==${VERSION}."
64+
exit 1
65+
66+
- name: Clone Repo B
67+
run: |
68+
git clone "https://x-access-token:${GH_TOKEN}@github.com/${ORG}/${TARGET_REPO}.git"
69+
cd "${TARGET_REPO}"
70+
git config user.name "access-nri-bot"
71+
git config user.email "bot@access-nri.org"
72+
73+
- name: Create branch and update environment.yml
74+
working-directory: ${{ env.TARGET_REPO }}
75+
env:
76+
VERSION: ${{ steps.ver.outputs.version }}
77+
run: |
78+
BRANCH="bump-${{ env.PACKAGE }}-${VERSION}"
79+
git fetch origin "${TARGET_BRANCH}"
80+
git checkout -b "$BRANCH" "origin/${TARGET_BRANCH}"
81+
82+
# 1) Replace if present
83+
yq -i '(.dependencies[] | select(tag == "!!str" and test("^accessnri::access-mopper=="))) = "accessnri::access-mopper=="+env(VERSION)' "${FILE_PATH}"
84+
85+
# 2) If still missing, append to the list
86+
if ! yq '.dependencies[] | select(tag == "!!str")' "${FILE_PATH}" | grep -q "^accessnri::access-mopper==${VERSION}$"; then
87+
yq -i '.dependencies += ["accessnri::access-mopper=="+env(VERSION)]' "${FILE_PATH}"
88+
fi
89+
90+
echo "Final dependency line:"
91+
yq '.dependencies[] | select(tag == "!!str")' "${FILE_PATH}" | grep accessnri::access-mopper || true
92+
93+
git add "${FILE_PATH}"
94+
if git diff --cached --quiet; then
95+
echo "No changes to commit (already at desired version)."
96+
echo "changed=false" >> $GITHUB_OUTPUT
97+
else
98+
git commit -m "analysis3: bump access-mopper to ${VERSION}"
99+
git push -u origin "$BRANCH"
100+
echo "changed=true" >> $GITHUB_OUTPUT
101+
fi
102+
103+
- name: Create PR (idempotent)
104+
if: ${{ success() }}
105+
working-directory: ${{ env.TARGET_REPO }}
106+
env:
107+
VERSION: ${{ steps.ver.outputs.version }}
108+
run: |
109+
BRANCH="bump-${{ env.PACKAGE }}-${VERSION}"
110+
# If a PR already exists for this branch, this returns non-zero; ignore errors.
111+
gh pr create \
112+
--base "${TARGET_BRANCH}" \
113+
--head "${BRANCH}" \
114+
--title "Bump ${PACKAGE} to ${VERSION} in analysis3 env" \
115+
--body "Updates \`${FILE_PATH}\` to \`accessnri::access-mopper==${VERSION}\`."
116+
117+
# Capture PR number for the next step
118+
gh pr view --json number -q .number > ../pr_number.txt || true
119+
120+
- name: Enable auto-merge
121+
working-directory: ${{ env.TARGET_REPO }}
122+
run: |
123+
if [ -f ../pr_number.txt ]; then
124+
PR=$(cat ../pr_number.txt)
125+
# Choose one of: --merge | --squash | --rebase
126+
gh pr merge "$PR" --auto --merge
127+
echo "Auto-merge enabled on PR #$PR."
128+
else
129+
echo "No PR number found (maybe PR already existed). Enabling auto-merge anyway…"
130+
gh pr merge --auto --merge || true
131+
fi

0 commit comments

Comments
 (0)