diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..8472ddd --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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 }}." \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ef6914 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.secrets diff --git a/README.md b/README.md index 1a931ae..fd1844e 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/action.yml b/action.yml index 9b5e391..f8b2352 100644 --- a/action.yml +++ b/action.yml @@ -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