Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add CI test for action #13

Merged
merged 13 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 12 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
38 changes: 38 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: test
on:
workflow_dispatch:
pull_request:
push:
branches:
- 'main'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Move local action to folder where it can be tested
shell: bash
run: |
mkdir -p .github/actions/test
cp action.yml .github/actions/test/action.yml

- uses: ./.github/actions/test
with:
service-key: ${{ secrets.SERVICE_KEY }}

- name: (optional) Twingate logs
run: journalctl -u twingate

- name: (optional) Twingate status
run: twingate status

- name: Access a secure resource
env:
TEST_URL: http://business.prod.beamreachinc.int/
run: |
echo Calling $TEST_URL 🚀
curl -v $TEST_URL

- run: echo "SUCCESS!!! 🤩 This job's status is ${{ job.status }}."
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.secrets
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ There are two common use cases:
# Required
service-key: ${{ secrets.EXAMPLE_SERVICE_KEY_SECRET_NAME }}
```


# Development

To run action locally to debug you can use `act` (`brew install act`):
```
act -j test -s SERVICE_KEY --container-options "--cap-add NET_ADMIN --device /dev/net/tun"
```

It'll ask for `SERVICE_KEY` value interactively.
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,36 @@ runs:
- name: Install Twingate
shell: bash
run: |
sudo apt update
echo "deb [trusted=yes] https://packages.twingate.com/apt/ /" | sudo tee /etc/apt/sources.list.d/twingate.list
sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/twingate.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
sudo apt install -yq twingate
- name: Setup and start Twingate
shell: bash
run: |
echo '${{ inputs.service-key }}' | sudo twingate setup --headless=-
echo '${{ inputs.service-key }}' | sudo twingate setup --headless -
MAX_RETRIES=5
WAIT_TIME=5
n=0

while [ $n -lt $MAX_RETRIES ]; do
echo "Starting Twingate service..."
set +xe
sudo twingate start

echo "Waiting $WAIT_TIME seconds for Twingate service to start..."
sleep $WAIT_TIME

status=$(sudo twingate status)
status=$(twingate status)
echo "Twingate service status: '$status'"

if [ "$status" = "online" ]; then
echo "Twingate service is connected."
twingate resources
break
else
sudo twingate stop
journalctl -u twingate --no-pager
fi

# Increment the retry counter and wait time
Expand Down
Loading