diff --git a/build/action.yml b/build/action.yml index f50b975..f9d90bf 100644 --- a/build/action.yml +++ b/build/action.yml @@ -49,6 +49,10 @@ inputs: default: false gh_event: description: The name of the event that triggered the parent workflow. +outputs: + ghc_img: + description: "Export GHCR.io package resource URL" + value: ${{ steps.ghc_img_id.outputs.ghc_img }} runs: using: composite @@ -142,3 +146,8 @@ runs: cache-from: type=gha cache-to: type=gha,mode=max provenance: false + + - name: Export GHCR.io resource + id: ghc_img_id + shell: bash + run: echo "ghc_img=${{ inputs.image }}:${{ steps.tag_check.outputs.tag }}" >> $GITHUB_OUTPUT diff --git a/deploy/action.yml b/deploy/action.yml new file mode 100644 index 0000000..70cdb42 --- /dev/null +++ b/deploy/action.yml @@ -0,0 +1,66 @@ +name: Deploy +description: "This action is used to deploy" + +inputs: + environment: + required: false + description: the github actions environment context + image: + required: true + description: The full gchr image + file: + required: true + description: path to file in repository to update with the image + CONFIG_REPO_RW_APP_ID: + description: The ID of the GithubApp that is used to generate keys that enable one repository to send repository dispatch messages to another. + required: true + CONFIG_REPO_RW_INSTALL_ID: + description: "" + required: false + CONFIG_REPO_FULL_NAME: + description: The github repo of the tanka control repository + required: true + # secrets: + CONFIG_REPO_RW_KEY: + description: The private key used to talk to the GithubAPP with the App ID + required: true + +runs: + using: composite + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set environment variables + shell: bash + run: | + if [ -z "${{ inputs.CONFIG_REPO_RW_APP_ID }}" ] + then + echo "CONFIG_REPO_RW_APP_ID=${{ env.CONFIG_REPO_RW_APP_ID }}" >> $GITHUB_ENV + echo "setting CONFIG_REPO_RW_APP_ID to ${{ env.CONFIG_REPO_RW_APP_ID }} from env" + else + echo "CONFIG_REPO_RW_APP_ID=${{ inputs.CONFIG_REPO_RW_APP_ID }}" >> $GITHUB_ENV + echo "setting CONFIG_REPO_RW_APP_ID to ${{ inputs.CONFIG_REPO_RW_APP_ID }} from inputs" + fi + if [ -z "${{ inputs.CONFIG_REPO_FULL_NAME }}" ] + then + echo "CONFIG_REPO_FULL_NAME=${{ env.CONFIG_REPO_FULL_NAME }}" >> $GITHUB_ENV + echo "setting CONFIG_REPO_FULL_NAME to ${{ env.CONFIG_REPO_FULL_NAME }} from env" + else + echo "CONFIG_REPO_FULL_NAME=${{ inputs.CONFIG_REPO_FULL_NAME }}" >> $GITHUB_ENV + echo "setting CONFIG_REPO_FULL_NAME to ${{ inputs.CONFIG_REPO_FULL_NAME }} from inputs" + fi + - name: Generate app token + id: generate_token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ env.CONFIG_REPO_RW_APP_ID }} + private-key: ${{ inputs.CONFIG_REPO_RW_KEY }} + owner: ${{ github.repository_owner }} + - name: Send the message + uses: peter-evans/repository-dispatch@v3 + with: + event-type: update-image + token: ${{ steps.generate_token.outputs.token }} + repository: ${{ env.CONFIG_REPO_FULL_NAME }} + client-payload: '{ "subject": "Update ${{ inputs.file }}", "body": "Originating repository is ${{ github.repository }}\nRun ID is ${{ github.run_id }}\nUser is ${{ github.actor }}", "image": "${{ inputs.image }}", "file": "${{ inputs.file }}" }' diff --git a/update-image/action.yml b/update-image/action.yml new file mode 100644 index 0000000..df14f33 --- /dev/null +++ b/update-image/action.yml @@ -0,0 +1,48 @@ +name: Update Image File +description: Updates the image file in the ht_tanka repository + +inputs: + subject: + required: true + description: '' + body: + required: true + description: '' + image: + required: true + description: '' + file: + required: true + description: '' + +runs: + using: composite + steps: + - name: Clone latest repository + uses: actions/checkout@v4 + - name: dump github event + shell: bash + env: + EVENT: ${{ toJson(github.event) }} + run: echo "$EVENT" + - name: update the config + shell: bash + env: + FILE: ${{ inputs.file }} + IMAGE: ${{ inputs.image }} + run: echo -n $IMAGE > $FILE + - name: cat the files + shell: bash + run: cat ${{ inputs.file }} + - name: Commit and push files new file + shell: bash + env: + SUBJECT: ${{ inputs.subject }} + BODY: ${{ inputs.body }} + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Actions Bot" + git pull + git add -A + git commit -m "$SUBJECT" -m "$BODY" + git push