Skip to content

Commit

Permalink
Update workflow from projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Lubken committed Sep 23, 2024
1 parent 422117a commit c25ba7a
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 144 deletions.
93 changes: 35 additions & 58 deletions {{cookiecutter.name}}/.github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,63 @@ on:
- published

jobs:
publish:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
deploy: ${{ steps.info.outputs.deploy }}
version: ${{ steps.info.outputs.version }}

steps:
- id: checkout
uses: actions/checkout@v4

- id: version
- id: info
run: |
version=$(./scripts/version.sh)
echo "version = ${version}"
echo "version=${version}" >> $GITHUB_OUTPUT
./scripts/info.sh >> $GITHUB_OUTPUT
- id: publish
run: |
./scripts/publish.sh -b true -p "${{ secrets.GITHUB_TOKEN }}" -v "${{ steps.version.outputs.version }}"
./scripts/publish.sh \
--build true \
--password "${{ secrets.GITHUB_TOKEN }}" \
--version "${{ steps.info.outputs.version }}"
evaluation:
if: ${{ github.event.release.prerelease }}
needs: publish
runs-on: [evaluation, self-hosted, nomad, azure]
prepare:
needs: build
# matrix.deploy shows up in the GUI
strategy:
matrix:
deploy: [ '${{ needs.build.outputs.deploy }}' ]
runs-on: ubuntu-latest
# if prepare must happen on the runner
# runs-on: [self-hosted, nomad, '${{ needs.build.outputs.deploy }}' ]
steps:
- id: prepare
run: |
echo 'deploy: ${{ needs.build.outputs.deploy }}; version: ${{ needs.build.outputs.version }}'
deploy:
needs: [build, prepare]
runs-on: [self-hosted, nomad, '${{ needs.build.outputs.deploy }}' ]
steps:
- id: checkout
uses: actions/checkout@v4

{% endraw %}
# Deploy configuration
- id: consul
run: |
./scripts/consul.sh \
--src ./predict/local/configuration.yaml \
--dst pennsignals/{{ cookiecutter.name }}/predict/configuration.yaml
{% raw %}
# Deploy jobs

- id: nomad
run: |
./scripts/nomad.sh \
--src ./predict/nomad \
--dst ./nomad \
--version "${{ needs.publish.outputs.version }}"
# Upload rendered nomad jobs as artifacts
- id: upload
uses: actions/upload-artifact@v4
with:
name: nomad
path: nomad.tar.gz
--version "${{ needs.build.outputs.version }}"
# Add artifacts to release
- id: release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: softprops/action-gh-release@v2
Expand All @@ -64,41 +70,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

live:
if: ${{ !github.event.release.prerelease }}
needs: publish
runs-on: [live, self-hosted, nomad, azure]
results:
if: ${{ always() }}
runs-on: ubuntu-latest
needs: [deploy]
steps:
- id: checkout
uses: actions/checkout@v4
- id: results
if: ${{ needs.deploy.result != 'success' }}
run: exit 1
{% endraw %}
# Deploy configuration
- id: consul
run: |
./scripts/consul.sh \
--src ./predict/local/configuration.yaml \
--dst pennsignals/{{ cookiecutter.name }}/predict/configuration.yaml
{% raw %}
# Deploy jobs
- id: nomad
run: |
./scripts/nomad.sh \
--src ./predict/nomad
--dst ./nomad \
--version "${{ needs.publish.outputs.version }}"
# Upload rendered nomad jobs as artifacts
- id: upload
uses: actions/upload-artifact@v4
with:
name: nomad
path: nomad.tar.gz

# Add artifacts to release
- id: release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: softprops/action-gh-release@v2
with:
files: nomad.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}{% endraw %}
44 changes: 24 additions & 20 deletions {{cookiecutter.name}}/scripts/consul.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
#!/usr/bin/env bash
set -euxo pipefail
set -euo pipefail

function usage {
echo ""
echo "Consul configuration put."
echo ""
echo "usage: --src ./predict/local/configuration.yaml --dst organization/application/predict/configuration.yaml"
echo ""
echo " --src -s string path to configuration file"
echo " --dst -d string path to consul kv"
echo " --help -t Print usage and exit"
echo ""
cat << EOF
Usage: $0 [options]
Options:
-s, --src string Path to configuration file
(example: ./predict/local/configuration.yaml)
-d, --dst string Path to consul key value
(example: organization/application/predict/configuration.yaml
-h, --help Print this help and exit
EOF
}

while [ $# -gt 0 ]; do
while (( "$#" )); do
case "$1" in
-h|--help)
usage
exit 0
;;
-d|--dst)
dst="$2"
;;
shift 2
;;
-s|--src)
src="$2"
;;
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
invalid_parameter $1
echo "Error: Invalid argument $1" >&2
usage
exit 1
;;
esac
shift
shift
done

consul kv put ${dst} @${src}
64 changes: 64 additions & 0 deletions {{cookiecutter.name}}/scripts/info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -euo pipefail

usage() {
cat << EOF
Usage: $0 [options]
Options:
-r, --ref string GitHub ref (default: GITHUB_REF env var)
-s, --sha string GitHub SHA (default: GITHUB_SHA env var)
-h, --help Print this help and exit
If not provided via command-line arguments, GITHUB_REF and GITHUB_SHA
must be set in the environment.
EOF
}

# Parse command line arguments
while (( "$#" )); do
case "$1" in
-r|--ref)
ref="$2"
shift 2
;;
-s|--sha)
sha="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Error: Invalid argument $1" >&2
usage
exit 1
;;
esac
done

# Set variable, fail if it is not provided and not in the environment
ref="${ref:=$GITHUB_REF}"
deploy=""

if [[ "$ref" == refs/tags/* ]]; then
version=$(basename "$ref")
regex="^[0-9]+\.[0-9]+\.[0-9]+(-(rc|evaluation)\.([0-9]+))?$"
# Check if the version matches semantic versioning pattern
if [[ $version =~ $regex ]]; then
# Extract deploy from the version
deploy="${BASH_REMATCH[2]}"
if [[ $deploy == "" ]]; then
deploy="live"
fi
fi
else
# Set variable, fail if it is not provided and not in the environment
sha="${sha:=$GITHUB_SHA}"
version="$sha"
fi

# Output variables in GitHub Actions output format
echo "version=${version}"
echo "deploy=${deploy}"
51 changes: 29 additions & 22 deletions {{cookiecutter.name}}/scripts/nomad.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
#!/usr/bin/env bash
set -euxo pipefail
set -euo pipefail

function usage {
echo ""
echo "Publish labeled images from docker compose."
echo ""
echo "usage: --src -s ./predict/nomad --dst -d ./nomad"
echo ""
echo " --src -s string Source directory for nomad files"
echo " --dst -d string Destination for rendered nomad files"
echo " --version -v string version"
echo " (example: 4.0.0-rc.1)"
echo " --help -h Print usage and exit"
echo ""
cat << EOF
Usage: $0 [options]
Levant render and deploy nomad jobs.
Options:
-s, --src string Source directory for nomad files
(example: ./predict/nomad)
-d, --dst string Destination directory for rendered files
(example: ./nomad)
-v, --version string Version
(example: 4.0.0-rc.1)
-h, --help Print this help and exit
EOF
}

while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-s|--src)
src="$2"
;;
shift 2
;;
-d|--dst)
dst="$2"
;;
shift 2
;;
-v|--version)
version="$2"
;;
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
invalid_parameter $1
echo "Error: Invalid argument $1" >&2
usage
exit 1
;;
esac
shift
shift
done

echo "Deploying jobs from: ${src}"
Expand Down
Loading

0 comments on commit c25ba7a

Please sign in to comment.