Skip to content

Commit

Permalink
Add action
Browse files Browse the repository at this point in the history
  • Loading branch information
kitallis committed Sep 1, 2023
1 parent 1b6ee0e commit b5e010e
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test

on:
push:
workflow_dispatch:
inputs:
tramline-input:
required: false

jobs:
deploy_job:
runs-on: ubuntu-latest
name: A job to test tramline deploys
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy
uses: ./ # Uses the action in the root directory
id: tramline
with:
input: ${{ github.event.inputs.tramline-input }}
- name: Get the output
run: |
echo "vcode: ${{ steps.tramline.outputs.version_code }}"
echo "vname: ${{ steps.tramline.outputs.version_name }}"
echo "cref: ${{ steps.tramline.outputs.commit_ref }}"
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Container image that runs your code
FROM alpine:3.10

# Copies your code file from your action repository to the filesystem path `/` of the container
COPY entrypoint.sh /entrypoint.sh

# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/entrypoint.sh"]
30 changes: 30 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# action.yml
name: 'Configure Tramline'
description: 'Checkout the correct ref & parse JSON inputs'
inputs:
input:
description: "Input from Tramline as a JSON blob"
required: true
default: "{}"
outputs:
version_code:
description: 'the version code (build number) for the build'
value: ${{ steps.tramline.outputs.version_code }}
version_name:
description: 'the version name for the build'
value: ${{ steps.tramline.outputs.version_name }}
commit_ref:
description: 'the commit for which this workflow is triggered'
value: ${{ steps.tramline.outputs.commit_ref }}
runs:
using: "composite"
steps:
- name: Parse inputs from Tramline
run: ./parse_inputs.sh ${{ inputs.input }}
id: tramline
shell: bash

- name: Checkout the repo
uses: actions/checkout@v3
with:
ref: ${{ steps.tramline.outputs.commit_ref }}
43 changes: 43 additions & 0 deletions parse_inputs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash -l

echo "Starting tramline input parsing..."

# Install jq if it doesn't exist
if ! command -v jq &> /dev/null
then
echo "jq is not installed. Installing..."
sudo apt-get update
sudo apt-get install -y jq
else
echo "jq is already installed. Skipping..."
fi

# Parse JSON and store keys in an array
echo $1 > tramline_input.json
keys=()
while read -r value
do
keys+=("$value")
done < <(jq -c 'keys_unsorted[]' tramline_input.json)

# Exit if there are parse errors
if [ -z "$keys" ]; then
echo "Error parsing Tramline inputs. Exiting..."
exit 1
fi

# Loop through the keys and set variables
for key in "${keys[@]}"; do
# Get the value of the key from JSON
value=$(jq -r ".$key" tramline_input.json)
# Remove double quotes from key
key="${key//\"/}"
# Assign the value to a variable with a name based on the key
output="${key}=${value}"
# Output
echo $output >> "$GITHUB_OUTPUT"
done

# Cleanup
rm -f tramline_input.json
echo "Finishing up tramline input parsing..."

0 comments on commit b5e010e

Please sign in to comment.