Skip to content

Commit 3296d51

Browse files
authored
Merge pull request #28 from FusionAuth/jj/remove-self-hosted-runner
Jj/remove self hosted runner
2 parents 46e84a8 + 4651fc6 commit 3296d51

File tree

2 files changed

+164
-24
lines changed

2 files changed

+164
-24
lines changed

.github/workflows/deploy.yaml

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# Run locally with act:
2-
#
3-
# act pull_request [--input command=[command]] \
4-
# --platform fusionauth-standard=[ecr-repo-name]/fusionauth-standard:latest] \
5-
# --workflows ./.github/workflows/deploy.yaml \
6-
# --env-file <(aws configure export-credentials --profile [aws-profile] --format env)
7-
1+
---
82
name: Deploy
93

104
on:
@@ -28,37 +22,54 @@ permissions:
2822
contents: read
2923

3024
jobs:
31-
build:
32-
if: |
33-
github.event_name == 'pull_request' ||
34-
github.event_name == 'push' ||
35-
github.event_name == 'workflow_dispatch' && inputs.command == 'build'
36-
runs-on: fusionauth-standard
25+
deploy:
26+
runs-on: ubuntu-latest
27+
defaults:
28+
run:
29+
shell: /usr/bin/bash -l -e -o pipefail {0}
3730
steps:
3831
- name: checkout
3932
uses: actions/checkout@v4
4033

34+
- name: setup java
35+
uses: actions/setup-java@v4
36+
with:
37+
distribution: temurin
38+
java-version: 21
39+
java-package: jre
40+
41+
- name: install savant
42+
run: |
43+
curl -O https://repository.savantbuild.org/org/savantbuild/savant-core/2.0.0/savant-2.0.0.tar.gz
44+
tar xzvf savant-2.0.0.tar.gz
45+
savant-2.0.0/bin/sb --version
46+
SAVANT_PATH=$(realpath -s "./savant-2.0.0/bin")
47+
echo "${SAVANT_PATH}" >> $GITHUB_PATH
48+
mkdir -p ~/.savant/plugins
49+
cat << EOF > ~/.savant/plugins/org.savantbuild.plugin.java.properties
50+
21=${JAVA_HOME}
51+
EOF
52+
53+
# Installs the version specified in the .ruby-version file in the repo root.
54+
- name: install ruby
55+
uses: ruby/setup-ruby@v1
56+
4157
- name: compile
4258
shell: bash -l {0}
4359
run: sb compile
4460

45-
deploy:
46-
if: |
47-
github.event_name == 'workflow_dispatch' &&
48-
(inputs.command == 'release' || inputs.command == 'publish')
49-
runs-on: fusionauth-standard
50-
steps:
51-
- name: checkout
52-
uses: actions/checkout@v4
61+
### Everything below this line will only run on a workflow_dispatch
5362

5463
- name: set aws credentials
64+
if: inputs.command == 'release' || inputs.command == 'publish'
5565
uses: aws-actions/configure-aws-credentials@v4
5666
with:
57-
role-to-assume: arn:aws:iam::752443094709:role/github-actions
67+
role-to-assume: arn:aws:iam::752443094709:role/gha-fusionauth-ruby-client
5868
role-session-name: aws-auth-action
5969
aws-region: us-west-2
6070

6171
- name: get secret
72+
if: inputs.command == 'release' || inputs.command == 'publish'
6273
run: |
6374
while IFS=$'\t' read -r key value; do
6475
echo "::add-mask::${value}"
@@ -71,17 +82,16 @@ jobs:
7182
jq -r 'to_entries[] | [.key, .value] | @tsv')
7283
7384
- name: set gem credentials
85+
if: inputs.command == 'release' || inputs.command == 'publish'
7486
run: |
7587
mkdir -p ~/.gem
7688
echo ":rubygems_api_key: ${{ env.API_KEY }}" > ~/.gem/credentials
7789
chmod 600 ~/.gem/credentials
7890
7991
- name: release to svn
8092
if: inputs.command == 'release'
81-
shell: bash -l {0}
8293
run: sb release
8394

8495
- name: publish to rubygems
8596
if: inputs.command == 'publish'
86-
shell: bash -l {0}
8797
run: sb publish

run-act.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
EVENT="workflow_dispatch"
8+
INPUTS=""
9+
PARSED_INPUTS=()
10+
PROFILE=""
11+
VERBOSE=false
12+
WORKFLOW=""
13+
14+
# Script metadata. Don't modify this.
15+
MYDIR=$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)
16+
cd "${MYDIR}"
17+
MYNAME=$(basename "$0")
18+
19+
# Configure colorful messages.
20+
GRAY=$(tput setaf 248)
21+
GREEN=$(tput setaf 2)
22+
RED=$(tput setaf 202)
23+
RESET=$(tput sgr0)
24+
25+
# Output formatting.
26+
function success() { echo -e "${GREEN}${1}${RESET}"; }
27+
function info() { echo -e "${GRAY}${1}${RESET}"; }
28+
function error() { echo -e "${RED}ERROR: ${1}${RESET}" >&2; }
29+
function fail() { echo -e "\n${RED}ERROR: ${1}${RESET}" >&2; exit 1; }
30+
function argerr() { echo -e "\n${RED}ERROR: ${1}${RESET}" >&2; show_help; }
31+
32+
# Helper functions.
33+
function file_missing() { if [[ -f "${1}" ]]; then return 1; else return 0; fi }
34+
35+
function show_help() {
36+
echo -e "\nUsage: ${MYNAME} --workflow [workflow-name.yaml] --profile [aws-profile-name]\n"
37+
echo -e " Flags Description Req Default"
38+
echo -e " ------------- ---------------------------- --- -------------------"
39+
echo -e " -e --event Github event to simulate workflow_dispatch"
40+
echo -e " -i --inputs CSV list of k/v pairs * ${GRAY}null${RESET}"
41+
echo -e " -p --profile AWS profile to use for auth Y ${GRAY}null${RESET}"
42+
echo -e " -v --verbose Enable verbose mode (set -xv) ${GRAY}disabled${RESET}"
43+
echo -e " -w --workflow Path/file of workflow to run Y ${GRAY}null${RESET}"
44+
echo -e " -h --help Show this message\n"
45+
echo -e " * --inputs requirements are determined by the workflow.\n"
46+
echo -e "See https://nektosact.com/ for more info about 'act'.\n"
47+
exit
48+
}
49+
50+
51+
function parse_args() {
52+
# Parse the args.
53+
while [[ $# -gt 0 ]]; do
54+
case $1 in
55+
-e|--event) shift
56+
if (( $# < 1 )); then argerr "--event requires an event type [push|pull_request|workflow_dispatch]"
57+
else EVENT="${1}"; fi
58+
shift;;
59+
-i|--inputs) shift
60+
if (( $# < 1 )); then argerr "--inputs requires a csv list of input args"
61+
else INPUTS="${1}"; fi
62+
shift;;
63+
-p|--profile) shift
64+
if (( $# < 1 )); then argerr "--profile requires an AWS profile name"
65+
else PROFILE="${1}"; fi
66+
shift;;
67+
-w|--workflow) shift
68+
if (( $# < 1 )); then argerr "--workflow requires a path to a workflow file"
69+
else WORKFLOW="${1}"; fi
70+
shift;;
71+
-v|--verbose) VERBOSE=true; shift;;
72+
-h|--help) show_help;;
73+
*) argerr "Unknown argument '$1'";;
74+
esac
75+
done
76+
77+
# Enable verbose mode if requested.
78+
if [ "${VERBOSE}" = true ]; then set -xv; fi
79+
80+
# Make sure --workflow is passed.
81+
if [[ -z "${WORKFLOW}" ]]; then argerr "--workflow is required"; fi
82+
# Make sure --workflow is passed.
83+
if [[ -z "${PROFILE}" ]]; then argerr "--profile is required"; fi
84+
# Make sure workflow file exists
85+
if file_missing "${WORKFLOW}"; then fail "Workflow '${WORKFLOW}' does not exist"; fi
86+
}
87+
88+
89+
function validate_prereqs() {
90+
local prereqs="act gh"
91+
for p in ${prereqs}; do
92+
if ! command -v "${p}" &>/dev/null; then
93+
error "${p} not found. Install it and try again."
94+
if [[ "${p}" == "gh" ]]; then
95+
info "\nAfter installing gh, login:"
96+
info " gh auth login"
97+
info "\nMake sure you can get a token:"
98+
info " gh auth token"
99+
fi
100+
exit 1
101+
fi
102+
done
103+
}
104+
105+
106+
function parse_inputs() {
107+
if [[ -n "${INPUTS}" ]]; then
108+
IFS=","
109+
for i in ${INPUTS}; do
110+
PARSED_INPUTS+=(--input "${i}")
111+
done
112+
fi
113+
}
114+
115+
116+
function main() {
117+
parse_args "$@"
118+
validate_prereqs
119+
parse_inputs
120+
121+
act "${EVENT}" \
122+
--secret GITHUB_TOKEN="$(gh auth token)" \
123+
--secret-file .env \
124+
--workflows "${WORKFLOW}" \
125+
--env-file <(aws configure export-credentials --profile "${PROFILE}" --format env) \
126+
"${PARSED_INPUTS[@]}"
127+
}
128+
129+
130+
main "$@"

0 commit comments

Comments
 (0)