update: test #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: | |
- '**' # すべてのブランチが対象 | |
permissions: | |
id-token: write # GitHub OIDCトークンの取得に必要な権限 | |
contents: read # リポジトリのコンテンツ読み取り権限 | |
jobs: | |
get-pods: | |
runs-on: ubuntu-latest | |
env: | |
CLOUDFLARE_TUNNEL_URL: "https://k8s-api.your-domain.com" # Kubernetes APIのURL | |
K8S_NAMESPACE: "default" # KubernetesのNamespace | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Authenticate and obtain OIDC token | |
id: auth | |
run: | | |
echo "Requesting OIDC token from GitHub..." | |
# GitHubが提供する環境変数を使用して、OIDCトークンを取得 | |
ID_TOKEN=$(curl -s -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ | |
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r '.value') | |
if [ -z "$ID_TOKEN" ]; then | |
echo "ERROR: Failed to retrieve OIDC token." | |
exit 1 | |
fi | |
echo "OIDC Token retrieved successfully." | |
echo "ID_TOKEN=$ID_TOKEN" >> $GITHUB_ENV # ID_TOKENを環境変数にエクスポート | |
- name: Get Kubernetes Pods from API | |
run: | | |
echo "Fetching pods from Kubernetes API at $CLOUDFLARE_TUNNEL_URL..." | |
# Kubernetes APIのGETリクエスト | |
API_URL="$CLOUDFLARE_TUNNEL_URL/api/v1/namespaces/$K8S_NAMESPACE/pods" | |
RESPONSE=$(curl -s -X GET $API_URL \ | |
-H "Authorization: Bearer $ID_TOKEN" \ | |
-H "Accept: application/json") | |
echo "Response from API:" | |
echo $RESPONSE | jq |