Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/obs-service-shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ on:
OBS_PASSWORD:
required: true

env:
obs_project: ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}

jobs:
update_service:
# do not run in forks which do not set the OBS_PROJECTS and OBS_USER variables,
# or the mapping for the current branch is missing
# (BTW, jobs.FOO.if cannot see env.*)
if: vars.OBS_PROJECTS && fromJson(vars.OBS_PROJECTS)[github.ref_name] && vars.OBS_USER

runs-on: ubuntu-latest
Expand Down Expand Up @@ -65,11 +69,11 @@ jobs:
OBS_USER: ${{ vars.OBS_USER }}
OBS_PASSWORD: ${{ secrets.OBS_PASSWORD }}

- name: Commit the rubygem-agama-yast package to ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
- name: Commit the rubygem-agama-yast package to ${{ env.obs_project }}
run: rake osc:commit
working-directory: ./service
env:
# do not build the package with "osc", it takes long time
# and does not provide much value
SKIP_OSC_BUILD: 1
OBS_PROJECT: ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
OBS_PROJECT: ${{ env.obs_project }}
10 changes: 6 additions & 4 deletions .github/workflows/obs-staging-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
# allow running manually
workflow_dispatch:

env:
obs_project: ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}

jobs:
test:

Expand All @@ -27,7 +30,6 @@ jobs:
echo 'vars.OBS_PROJECTS: ${{ vars.OBS_PROJECTS }}'
echo 'parsed vars.OBS_PROJECTS: ${{ fromJson(vars.OBS_PROJECTS) }}'
echo 'github.ref_name: ${{ github.ref_name }}'
echo 'Target OBS project: ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}'
echo 'Submit condition: ${{ vars.OBS_PROJECTS && fromJson(vars.OBS_PROJECTS)[github.ref_name] && vars.OBS_USER }}'
echo 'Submit would start: ${{ !contains(fromJSON('[false, 0, -0, "", null]'), vars.OBS_PROJECTS && fromJson(vars.OBS_PROJECTS)[github.ref_name] && vars.OBS_USER) }}'

echo 'Target OBS project: ${{ env.obs_project }}'
echo 'Submit condition: ${{ vars.OBS_PROJECTS && env.obs_project && vars.OBS_USER }}'
echo 'Submit would start: ${{ !!(vars.OBS_PROJECTS && env.obs_project && vars.OBS_USER) }}'
10 changes: 7 additions & 3 deletions .github/workflows/obs-staging-live.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ on:
# allow running manually
workflow_dispatch:

env:
obs_project: ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}

jobs:
update_obs_package:
# do not run in forks which do not set the OBS_PROJECTS variable,
# or the mapping for the current branch is missing
# (BTW, jobs.FOO.if cannot see env.*)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. That doc uses env for jobs.<job_id>.steps.if, but env is not available for jobs.<job_id>.if. Beautiful, right?

https://docs.github.com/en/actions/reference/workflows-and-actions/contexts#context-availability

if: vars.OBS_PROJECTS && fromJson(vars.OBS_PROJECTS)[github.ref_name] && vars.OBS_USER

runs-on: ubuntu-latest
Expand Down Expand Up @@ -44,8 +48,8 @@ jobs:
OBS_USER: ${{ vars.OBS_USER }}
OBS_PASSWORD: ${{ secrets.OBS_PASSWORD }}

- name: Checkout ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }} agama-installer
run: osc co -o dist ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }} agama-installer
- name: Checkout ${{ env.obs_project }} agama-installer
run: osc co -o dist ${{ env.obs_project }} agama-installer
working-directory: ./live

- name: Build sources
Expand All @@ -60,6 +64,6 @@ jobs:
run: osc diff && osc status
working-directory: ./live/dist

- name: Commit agama-installer to ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
- name: Commit agama-installer to ${{ env.obs_project }}
run: osc commit -m "Updated to Agama $GITHUB_SHA"
working-directory: ./live/dist
37 changes: 25 additions & 12 deletions .github/workflows/obs-staging-shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ on:
required: false
type: string

env:
obs_project: ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}

jobs:
update_obs_package:
# do not run in forks which do not set the OBS_PROJECTS and OBS_USER variables,
# or the mapping for the current branch is missing
# (BTW, jobs.FOO.if cannot see env.*)
if: vars.OBS_PROJECTS && fromJson(vars.OBS_PROJECTS)[github.ref_name] && vars.OBS_USER

runs-on: ubuntu-latest
Expand Down Expand Up @@ -66,27 +70,34 @@ jobs:
OBS_USER: ${{ vars.OBS_USER }}
OBS_PASSWORD: ${{ secrets.OBS_PASSWORD }}

- name: Checkout ${{ inputs.package_name }} from ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
run: osc co ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }} ${{ inputs.package_name }}
- name: Checkout ${{ inputs.package_name }} from ${{ env.obs_project }}
run: osc co ${{ env.obs_project }} ${{ inputs.package_name }}

- name: Configure git
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Update service revision
# only when a tag has been pushed, or "release" branch updated
if: inputs.service_file != ''
run: |-
run: |
echo "Updating revision to \"${{ github.ref_name }}\""
sed -i -e 's#<param name="revision">.*</param>#<param name="revision">${{ github.ref_name }}</param>#' ${{ inputs.service_file }}
BEG='<param name="revision">'
END='</param>'
sed -i -e "s#${BEG}.*${END}#${BEG}${{ github.ref_name }}${END}#" ${{ inputs.service_file }}

- name: Copy optional service file
# patch the URL in the file so it works also from forks, forks also by
# default do not inherit the tags so remove the version format option if
# no tag is present
if: inputs.service_file != ''
run: |
sed -e 's#<param name="url">.*</param>#<param name="url">https://github.com/${{ github.repository }}.git</param>#' ${{ inputs.service_file }} > ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}/_service
if [ -z "$(git tag -l)" ]; then sed -i -e 's#<param name="versionformat">.*</param>##' ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}/_service; fi
OUT_SERVICE=./${{ env.obs_project }}/${{ inputs.package_name }}/_service
BEG='<param name="url">'
END='</param>'
SED_EXPR="s#${BEG}.*${END}#${BEG}https://github.com/${{ github.repository }}.git${END}#"
sed -e "${SED_EXPR}" ${{ inputs.service_file }} > $OUT_SERVICE
BEG='<param name="versionformat">'
if [ -z "$(git tag -l)" ]; then sed -i -e "s#${BEG}.*${END}##" $OUT_SERVICE; fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it is more readable now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is complex and dense, but IMHO better than the previous version

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it makes reading a bit harder as you do not see what sed is in fact doing. I ask AI how to make it more readable and here is AI proposal which is for me more readable ( but still it includes sed expressions :)

OUT_SERVICE="./${{ env.obs_project }}/${{ inputs.package_name }}/_service"
REPO_URL="https://github.com/${{ github.repository }}.git"

# Replace the URL parameter and output to the new file
sed "s#<param name=\"url\">.*</param>#<param name=\"url\">${REPO_URL}</param>#" \
  "${{ inputs.service_file }}" > "$OUT_SERVICE"

# Strip the versionformat parameter if there are no git tags
if [ -z "$(git tag -l)" ]; then 
  sed -i "s#<param name=\"versionformat\">.*</param>##" "$OUT_SERVICE"
fi

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this is a case where your using AI makes things (slightly) harder for your human counterparty, myself. Now I would have to transplant the result to the YAML file and retest it. If you trust the AI output, please make a patch or a commit for me :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I do not trust AI, but paste it here to demonstrate what I do not like at your patch...that sed regexp like in some variable elsewhere, so you need more processing of it. On other hand AI solution ( even if it can have bugs ) is more easier to read for me as there is sed regexp with some long tricky replacements in own variable which is easier to read ( at least for me ).


- name: Run services
run: |
Expand All @@ -95,13 +106,15 @@ jobs:
# downloaded NPM package tarballs and they are accidentally added to the
# OBS package, so delete any TGZ files present
rm -vf *.tgz
working-directory: ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}
working-directory: ./${{ env.obs_project }}/${{ inputs.package_name }}

- name: Check status
run: osc addremove && osc diff && osc status
working-directory: ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}
working-directory: ./${{ env.obs_project }}/${{ inputs.package_name }}

- name: Commit ${{ inputs.package_name }} to ${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}
run: |-
osc commit -m "Updated to $(sed -e '/^version:/!d' -e 's/version: *\(.*\)/\1/' agama.obsinfo) ($(sed -e '/^commit:/!d' -e 's/commit: *\(.*\)/\1/' agama.obsinfo))"
working-directory: ./${{ fromJson(vars.OBS_PROJECTS)[github.ref_name] }}/${{ inputs.package_name }}
- name: Commit ${{ inputs.package_name }} to ${{ env.obs_project }}
run: |
VERSION="$(sed -e '/^version:/!d' -e 's/version: *\(.*\)/\1/' agama.obsinfo)"
COMMIT="$(sed -e '/^commit:/!d' -e 's/commit: *\(.*\)/\1/' agama.obsinfo)"
osc commit -m "Updated to ${VERSION} (${COMMIT})"
working-directory: ./${{ env.obs_project }}/${{ inputs.package_name }}
4 changes: 2 additions & 2 deletions devel/branch2obs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ workflows=(obs-staging-live.yml obs-staging-products.yml obs-staging-rust.yml ob
if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null; then
for workflow in "${workflows[@]}"; do
echo "Starting GitHub Action $workflow..."
gh workflow run "$workflow" --ref "$BRANCH"
gh -R "$repo_slug" workflow run "$workflow" --ref "$BRANCH"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice..I fix that by using gh repo set-default, but your solution looks better.

done
else
echo "After creating the remote branch trigger the submission actions on the web"
echo "or run these commands:"
echo
for workflow in "${workflows[@]}"; do
echo " gh workflow run \"$workflow\" --ref \"$BRANCH\""
echo " gh -R \"$repo_slug\" workflow run \"$workflow\" --ref \"$BRANCH\""
done
fi

Expand Down
Loading