Skip to content

Commit b6854e6

Browse files
Merge pull request #1653 from cfengine/ENT-10487/master
Refactored github workflows and scripts to allow for additional artifacts to be saved
2 parents 54d0fe9 + df64e02 commit b6854e6

File tree

6 files changed

+63
-32
lines changed

6 files changed

+63
-32
lines changed

.github/workflows/build-using-buildscripts.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ name: Build dependencies and CFEngine hub package
22

33
on:
44
workflow_call:
5+
inputs:
6+
additional_artifacts:
7+
description: 'Additional files or directories to include in artifacts'
8+
default: ''
9+
required: false
10+
type: string
11+
512
secrets:
613
GH_ACTIONS_SSH_DEPLOY_KEY_ENTERPRISE_REPO:
714
required: true
@@ -14,7 +21,7 @@ on:
1421

1522
jobs:
1623
build_cfengine_hub_package:
17-
name: Build package and run selenium tests
24+
name: Build package
1825
runs-on: ubuntu-22.04
1926
steps:
2027
- name: Checkout Together Action
@@ -46,9 +53,10 @@ jobs:
4653
path: masterfiles
4754
ref: ${{steps.together.outputs.masterfiles || github.base_ref}}
4855

49-
- name: Checkout Buildscripts (current project)
56+
- name: Checkout Buildscripts
5057
uses: actions/checkout@v3
5158
with:
59+
repository: cfengine/buildscripts
5260
path: buildscripts
5361
fetch-depth: 20
5462

@@ -88,13 +96,13 @@ jobs:
8896
run: echo "DEPS_SHA=$(git log --pretty='format:%h' -1 -- .)" | tee -a ${GITHUB_ENV}
8997
working-directory: buildscripts/deps-packaging
9098

91-
- name: restore packages cache
99+
- name: restore artifacts cache
92100
uses: actions/cache/restore@v3
93101
with:
94-
path: packages
95-
key: packages-${{ env.PACKAGE_SHA }}
102+
path: artifacts
103+
key: artifacts-${{ env.PACKAGE_SHA }}
96104
restore-keys: |
97-
packages-${{ env.PACKAGE_SHA }}
105+
artifacts-${{ env.PACKAGE_SHA }}
98106
99107
- name: Restore dependency cache
100108
uses: actions/cache/restore@v3
@@ -106,12 +114,21 @@ jobs:
106114
deps-master
107115
deps
108116
117+
- name: restore configured and built core and nova projects
118+
uses: actions/cache/restore@v3
119+
with:
120+
path: build
121+
key: build-${{ env.PACKAGE_SHA }}
122+
restore-keys: |
123+
build-${{ env.PACKAGE_SHA }}
124+
125+
109126
- name: Build package in docker
110127
env:
111128
GH_ACTIONS_SSH_KEY_BUILD_ARTIFACTS_CACHE: ${{ secrets.GH_ACTIONS_SSH_KEY_BUILD_ARTIFACTS_CACHE }}
112129
run: |
113-
if [ ! -f packages/cfe*deb ]; then
114-
buildscripts/ci/docker-build-package.sh
130+
if [ ! -f artifacts/cfe*deb ]; then
131+
buildscripts/ci/docker-build-package.sh ${{ inputs.additional_artifacts }}
115132
fi
116133
117134
- name: Save dependency cache
@@ -120,11 +137,13 @@ jobs:
120137
path: cache
121138
key: deps-${{ github.base_ref }}-${{ env.DEPS_SHA }}
122139

123-
- name: Save packages cache
140+
- name: Save artifacts cache
124141
uses: actions/cache/save@v3
125142
with:
126-
path: packages
127-
key: packages-${{ env.PACKAGE_SHA }}
143+
path: |
144+
artifacts
145+
packages
146+
key: artifacts-${{ env.PACKAGE_SHA }}
128147

129148
- name: Save artifacts
130149
if: success() || failure()

.github/workflows/deployment-tests.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ jobs:
9090
run: echo "DEPS_SHA=$(git log --pretty='format:%h' -1 -- .)" | tee -a ${GITHUB_ENV}
9191
working-directory: buildscripts/deps-packaging
9292

93-
- name: restore packages cache
93+
- name: restore artifacts cache
9494
uses: actions/cache/restore@v3
9595
with:
96-
path: packages
97-
key: packages-${{ env.PACKAGE_SHA }}
96+
path: artifacts
97+
key: artifacts-${{ env.PACKAGE_SHA }}
9898
restore-keys: |
99-
packages-${{ env.PACKAGE_SHA }}
99+
artifacts-${{ env.PACKAGE_SHA }}
100100
101101
- name: Restore dependency cache
102102
uses: actions/cache/restore@v3
@@ -113,7 +113,7 @@ jobs:
113113
env:
114114
GH_ACTIONS_SSH_KEY_BUILD_ARTIFACTS_CACHE: ${{ secrets.GH_ACTIONS_SSH_KEY_BUILD_ARTIFACTS_CACHE }}
115115
run: |
116-
if [ ! -f packages/cfe*deb ]; then
116+
if [ ! -f artifacts/cfe*deb ]; then
117117
buildscripts/ci/docker-build-package.sh
118118
fi
119119
@@ -126,11 +126,11 @@ jobs:
126126
path: cache
127127
key: deps-${{ github.base_ref }}-${{ env.DEPS_SHA }}
128128

129-
- name: Save packages cache
129+
- name: Save artifacts cache
130130
uses: actions/cache/save@v3
131131
with:
132-
path: packages
133-
key: packages-${{ env.PACKAGE_SHA }}
132+
path: artifacts
133+
key: artifacts-${{ env.PACKAGE_SHA }}
134134

135135
- name: Save artifacts
136136
if: success() || failure()

ci/build.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22
# build cfengine hub package
3+
# $@ -- optional space separated paths to copy to artifacts
4+
35
set -ex
6+
7+
additional_artifacts="$@"
48
export PROJECT=nova
59
export NO_CONFIGURE=1
610
export BUILD_TYPE=DEBUG
@@ -30,9 +34,15 @@ time sudo rm -rf /var/cfengine
3034
time sudo rm -rf /opt/cfengine
3135
time ./buildscripts/build-scripts/install-dependencies
3236
time ./buildscripts/build-scripts/package
33-
sudo mkdir -p packages
34-
sudo cp cfengine-nova-hub/*.deb packages/ || true
35-
sudo cp cfengine-nova-hub/*.rpm packages/ || true
37+
38+
sudo mkdir -p artifacts
39+
sudo cp cfengine-nova-hub/*.deb artifacts/ || true
40+
sudo cp cfengine-nova-hub/*.rpm artifacts/ || true
41+
42+
for artifact_path in $additional_artifacts; do
43+
sudo cp -r "$artifact_path" artifacts/ || true
44+
done
45+
3646

3747
# todo maybe save the cache cp -R ~/.cache buildscripts/ci/cache
3848

ci/deployment-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function failure() {
2727
}
2828

2929
if [ ! -d /var/cfengine ]; then
30-
# ci and local buildscripts should place built packages in $NTECH_ROOT/packages
31-
sudo dpkg -i "$NTECH_ROOT"/packages/cfengine-nova-hub*deb
30+
# ci and local buildscripts should place built packages in $NTECH_ROOT/artifacts
31+
sudo dpkg -i "$NTECH_ROOT"/artifacts/cfengine-nova-hub*deb
3232
fi
3333

3434

ci/docker-build-package.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22
# run the build in a docker container
3+
# $@ -- additional artifact paths to save
4+
additional_artifacts="$@"
35
set -ex
46

57
# find the dir two levels up from here, home of all the repositories
@@ -19,7 +21,7 @@ set +x # hide secrets
1921
if [ -n "$GH_ACTIONS_SSH_KEY_BUILD_ARTIFACTS_CACHE" ]; then
2022
export SECRET="$GH_ACTIONS_SSH_KEY_BUILD_ARTIFACTS_CACHE"
2123
else
22-
if ! export SECRET="$(pass mystiko/developers/CFEngine/jenkins/sftp-cache.sec)"; then
24+
if ! export SECRET="$(pass mystiko/developers/CFEngine/jenkins/jenkins_sftp_cache@github)"; then
2325
echo "The sftp cache ssh secret key must be provided, either with environment variable GH_ACTIONS_SSH_KEY_BUILD_ARTIFACTS_CACHE or access to mystiko path developers/CFEngine/jenkins/sftp-cache.sec"
2426
exit 1
2527
fi
@@ -29,7 +31,7 @@ set -x # done hiding secrets
2931
docker run -d --env SECRET --env JOB_BASE_NAME --privileged -v "${NTECH_ROOT}":/data --name $name $name
3032

3133
# copy local caches to docker container
32-
mkdir -p "${NTECH_ROOT}/packages"
34+
mkdir -p "${NTECH_ROOT}/artifacts"
3335
mkdir -p "${NTECH_ROOT}/cache"
3436

3537
# setup host key trust
@@ -49,14 +51,14 @@ docker exec -i $name bash -c "mkdir -p ~/.ssh"
4951
docker exec -i $name bash -c "echo $pubkey >> ~/.ssh/known_hosts"
5052

5153
docker exec -i $name bash -c 'cd /data; ./buildscripts/ci/setup-projects.sh'
52-
docker exec -i $name bash -c 'cd /data; ./buildscripts/ci/build.sh'
54+
docker exec -i $name bash -c "cd /data; ./buildscripts/ci/build.sh ${additional_artifacts}"
5355

54-
# save back cache and packages to host for handling by CI and such
56+
# save back cache and artifacts to host for handling by CI and such
5557
docker cp $name:/root/.cache/. "${NTECH_ROOT}/cache/"
56-
docker cp $name:/data/packages/. "${NTECH_ROOT}/packages/"
58+
docker cp $name:/data/artifacts/. "${NTECH_ROOT}/artifacts/"
5759

5860
rc=1 # if we find no packages, fail
59-
for f in packages/*.deb; do
61+
for f in artifacts/*.deb; do
6062
[ -f "$f" ] && rc=0
6163
break
6264
done

ci/docker-deployment-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ if docker ps -a | grep $name; then
2121
fi
2222
docker run -d --privileged -v "${NTECH_ROOT}":/data --name $name $name || true
2323

24-
if [ ! -d "${NTECH_ROOT}/packages" ]; then
25-
echo "${NTECH_ROOT}/packages directory should exist and have a cfengine-nova-hub package there"
24+
if [ ! -d "${NTECH_ROOT}/artifacts" ]; then
25+
echo "${NTECH_ROOT}/artifacts directory should exist and have a cfengine-nova-hub package there"
2626
exit 1
2727
fi
2828
docker exec -i $name bash -c 'cd /data; ./buildscripts/ci/deployment-tests.sh'

0 commit comments

Comments
 (0)