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

Update workflows #357

Merged
merged 9 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion .github/workflows/base-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ on:
schedule:
- cron: 0 1 * * 1

permissions:
contents: read

jobs:
push_image:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
name: Docker Images
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Registry login
run: |
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/labels.yaml

This file was deleted.

13 changes: 10 additions & 3 deletions .github/workflows/pull_request_review.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
name: pull_request_review test
name: Test pull_request_review event

on:
- pull_request_review

jobs:
apply:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
name: Apply approved changes on pull_request_review
permissions:
contents: read
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Plan
uses: ./terraform-plan
Expand All @@ -27,8 +32,10 @@ jobs:
path: tests/workflows/pull_request_review

- name: Verify outputs
env:
OUTPUT_STRING: ${{ steps.output.outputs.output_string }}
run: |
if [[ "${{ steps.output.outputs.output_string }}" != "the_string" ]]; then
if [[ "$OUTPUT_STRING" != "the_string" ]]; then
echo "::error:: output s not set correctly"
exit 1
fi
27 changes: 0 additions & 27 deletions .github/workflows/pull_request_review_trigger.yaml

This file was deleted.

18 changes: 14 additions & 4 deletions .github/workflows/pull_request_target.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
name: pull_request_target test
name: Test pull_request_target event

on:
- pull_request_target
- pull_request_target # zizmor: ignore[dangerous-triggers]

permissions:
contents: read

jobs:
apply:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
name: Apply approved changes on pull_request_target
permissions:
contents: read
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Plan
uses: ./terraform-plan
Expand All @@ -27,8 +35,10 @@ jobs:
path: tests/workflows/pull_request_target

- name: Verify outputs
env:
OUTPUT_STRING: ${{ steps.output.outputs.output_string }}
run: |
if [[ "${{ steps.output.outputs.output_string }}" != "the_string" ]]; then
if [[ "$OUTPUT_STRING" != "the_string" ]]; then
echo "::error:: output s not set correctly"
exit 1
fi
105 changes: 0 additions & 105 deletions .github/workflows/release-test.yaml

This file was deleted.

46 changes: 28 additions & 18 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ on:
description: "Tag to release"
required: true

permissions:
contents: read

jobs:
image:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
name: Release Actions
permissions:
contents: read
packages: write
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: true

- name: Check tofu actions are up to date
run: |
Expand All @@ -38,14 +46,14 @@ jobs:

- name: Build action image
id: image_build
env:
RELEASE_TAG: "${{ github.event.release.tag_name }}${{ github.event.inputs.tag_name }}"
run: |
RELEASE_TAG="${{ github.event.release.tag_name }}${{ github.event.inputs.tag_name }}"

docker buildx build \
--build-arg FETCH_CHECKSUMS=yes \
--build-arg VERSION="${RELEASE_TAG:1}" \
--tag danielflook/terraform-github-actions:$RELEASE_TAG \
--tag ghcr.io/dflook/terraform-github-actions:$RELEASE_TAG \
--tag "danielflook/terraform-github-actions:$RELEASE_TAG" \
--tag "ghcr.io/dflook/terraform-github-actions:$RELEASE_TAG" \
--platform linux/amd64,linux/arm64 \
--attest type=provenance,mode=max,builder-id=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID \
--push \
Expand All @@ -55,29 +63,31 @@ jobs:
echo "digest=$(<manifest-list-digest.txt)" >> "$GITHUB_OUTPUT"

- name: Release actions
env:
RELEASE_TAG: "${{ github.event.release.tag_name }}${{ github.event.inputs.tag_name }}"
IMAGE_DIGEST: ${{ steps.image_build.outputs.digest }}
run: |
export RELEASE_TAG="${{ github.event.release.tag_name }}${{ github.event.inputs.tag_name }}"
export major=$(echo $RELEASE_TAG | cut -d. -f1)
export minor=$(echo $RELEASE_TAG | cut -d. -f2)
export major=$(echo "$RELEASE_TAG" | cut -d. -f1)
export minor=$(echo "$RELEASE_TAG" | cut -d. -f2)

git config --global user.name "Daniel Flook"
git config --global user.email "[email protected]"

function prepare_release() {
rsync -r $GITHUB_WORKSPACE/$action/ $HOME/$action
rm -rf $HOME/$action/.github
mkdir $HOME/$action/.github
cp $GITHUB_WORKSPACE/.github/FUNDING.yml $HOME/$action/.github/FUNDING.yml
rsync -r "$GITHUB_WORKSPACE/$action/" "$HOME/$action"
rm -rf "$HOME/$action/.github"
mkdir "$HOME/$action/.github"
cp "$GITHUB_WORKSPACE/.github/FUNDING.yml" "$HOME/$action/.github/FUNDING.yml"
}

for action in $(cd $GITHUB_WORKSPACE && find . -name action.yaml -printf "%h\n" | sed 's/^.\///'); do
for action in $(cd "$GITHUB_WORKSPACE" && find . -name action.yaml -printf "%h\n" | sed 's/^.\///'); do

if git clone https://dflook:[email protected]/dflook/$action.git "$HOME/$action"; then
if git clone "https://dflook:[email protected]/dflook/$action.git" "$HOME/$action"; then
echo "Releasing dflook/$action@$RELEASE_TAG"

# git tags that use DockerHub for the image
prepare_release
sed -i 's| image:.*| image: docker://danielflook/terraform-github-actions@${{ steps.image_build.outputs.digest }}|' $HOME/$action/action.yaml
sed -i "s| image:.*| image: docker://danielflook/terraform-github-actions@$IMAGE_DIGEST|" "$HOME/$action/action.yaml"

git -C "$HOME/$action" add -A
git -C "$HOME/$action" commit -m "$RELEASE_TAG"
Expand All @@ -90,7 +100,7 @@ jobs:
# git tags that use GitHub Container Registry for the image
git -C "$HOME/$action" checkout ghcr || git -C "$HOME/$action" checkout -b ghcr
prepare_release
sed -i 's| image:.*| image: docker://ghcr.io/dflook/terraform-github-actions@${{ steps.image_build.outputs.digest }}|' $HOME/$action/action.yaml
sed -i "s| image:.*| image: docker://ghcr.io/dflook/terraform-github-actions@$IMAGE_DIGEST|" "$HOME/$action/action.yaml"

git -C "$HOME/$action" add -A
git -C "$HOME/$action" commit -m "$RELEASE_TAG-ghcr"
Expand All @@ -101,11 +111,11 @@ jobs:
git -C "$HOME/$action" push --force --tags

# Create the github release
cat $GITHUB_WORKSPACE/.github/release_template.md \
cat "$GITHUB_WORKSPACE/.github/release_template.md" \
| envsubst \
| jq --slurp --raw-input --arg RELEASE_TAG "$RELEASE_TAG" '{"tag_name": $RELEASE_TAG, "name": $RELEASE_TAG, "body": . }' \
| curl -X POST \
--user dflook:$GITHUB_TOKEN \
--user "dflook:$GITHUB_TOKEN" \
--header "Content-Type: application/json" \
--data-binary @- \
"https://api.github.com/repos/dflook/$action/releases"
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/repository_dispatch.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
name: Respository Dispatch
name: Repository Dispatch

on: [repository_dispatch]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

permissions:
contents: read

jobs:
plan:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
name: Create terraform plan
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
persist-credentials: false

- name: terraform plan
uses: ./terraform-plan
Expand Down
Loading
Loading