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

Optimizing GH actions, to use less minutes. (WIP) #1563

Closed
wants to merge 2 commits into from

Conversation

rasben
Copy link
Contributor

@rasben rasben commented Sep 13, 2024

We can use .lagoon.yml to set up a GH deployment, that we can use to listen for in GH actions.
This is an alternative to us spending a lot of GH minutes just waiting for the site to become available.

As the @todo's say, this needs some work, as I'm unsure how to use secrets and get around set -e as part of the deployment.
I'm looking for input for this :)

Ontop of that, also setting up concurrency rules to ci-tests, so if a second push is made, we cancel the old and unrelated workflow.

@rasben rasben added the help wanted Extra attention is needed label Sep 17, 2024
.lagoon.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@kasperg kasperg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the effort and I have tried to help out (a little) and provide feedback where I can.

Comment on lines +7 to +8
# @todo - this action does nothing useful right now, but it is to show that
# the site URL is available as part of deployment_status.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the comment but I suggest removing this file entirely.

As I see it we should not run tests on the deployed environment as implied in the workflow name. We do this on the corresponding environment established in CI.

Comment on lines 90 to 108
CloseEnvironment:
name: Close environment
runs-on: ubuntu-latest
if: ${{ github.event.action == 'closed' }}
permissions:
# Give the default GITHUB_TOKEN permission to close deployments.
deployments: write
steps:
- name: Generate environment data
id: environment
run: |
echo ::set-output name=id::pr-${{github.event.number}}
- name: Close environment
uses: bobheadxi/[email protected]
with:
step: deactivate-env
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ steps.environment.outputs.id }}
debug: ${{ runner.debug && 'true' || 'false' }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see it the current approach does not handle deactivating environments when the corresponding pull request is closed. I think it is a good idea to do so to avoid cluttering the project with obsolete environments which still show up as active.

As I see it Lagoon does not have a way to run code when closing an environment so I think it makes sense to keep this job as an alternate approach based on the fact that in practice closing a pull request will close the corresponding environment on Lagoon.

Comment on lines 110 to 130
# We only permit the integration with Lagoon to run if the user is
# authorized. This saves on resources and ensures we only spin up sites for
# legitimate contributions.
# The integration is controlled by creating synthetic events related to select
# pull-request events, and send them to Lagoon.
#
# The job expects the following secrets:
# LAGOON_WEBHOOK_URL: The url events are to be delivered to
# LAGOON_WEBHOOK_SECRET: Shared lagoon webhook secret
#
InformLagoon:
name: Send synthetic event to Lagoon
runs-on: ubuntu-latest
needs: [BranchNameLength]
steps:
- name: Send pull request event
uses: distributhor/workflow-webhook@v3
env:
webhook_url: ${{ secrets.LAGOON_WEBHOOK_URL }}
webhook_secret: ${{ secrets.LAGOON_WEBHOOK_SECRET }}
webhook_type: 'json-extended'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reconsider deleting this job.

This is the one that informs Lagoon about changes to pull requests so without this new pull request environments will not be created.

.lagoon.yml Outdated
- run:
name: Create new GH deployment
command: |
# @TODO Where can i place the token as a secret?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider mentioning that we do not use set -e as we do not want the build process to stop if deployment handling fails.

Comment on lines 15 to 27
BranchNameLength:
name: Check branch length
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Ensure branch name length
uses: lekterable/[email protected]
if: github.ref_type == 'branch' || github.ref_type == 'pull_request'
with:
allowed: |
/^.{1,100}$/
errorMessage: 'Branch name too long. This cannot be deployed to Lagoon.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep the Lagoon workflow around then I suggest moving this job back.

.lagoon.yml Outdated
Comment on lines 107 to 116
# @TODO How do we run this, even if something has gone wrong?
- run:
name: Setting Deployment status
command: |
# @TODO How do we set this to 'failure', if something has gone wrong?
DEPLOYMENT_STATUS="success";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kasperg kasperg removed their assignment Sep 18, 2024
@rasben rasben assigned rasben and unassigned achton Sep 20, 2024
@rasben rasben force-pushed the optimize-gh-actions branch 5 times, most recently from b54d954 to 55449a8 Compare October 1, 2024 21:55
@dpl-platform-bot dpl-platform-bot requested a deployment to production October 1, 2024 22:17 Abandoned
@rasben rasben force-pushed the optimize-gh-actions branch 3 times, most recently from bf8d8f6 to 3d7bc76 Compare October 1, 2024 22:38
@dpl-platform-bot dpl-platform-bot requested a deployment to production October 1, 2024 22:56 Abandoned
@dpl-platform-bot dpl-platform-bot requested a deployment to production October 1, 2024 22:57 Abandoned
@rasben rasben force-pushed the optimize-gh-actions branch 7 times, most recently from 7103aed to 3d014a1 Compare October 2, 2024 09:10
@dpl-platform-bot dpl-platform-bot requested a deployment to production October 2, 2024 09:14 Abandoned
@dpl-platform-bot dpl-platform-bot temporarily deployed to e4bb82a64adf32dd9699636b572383cff1a5e20d October 2, 2024 09:23 Inactive
We can use `.lagoon.yml` to set up a GH deployment,
that we can use to listen for in GH actions.
This is an alternative to us spending a lot of GH minutes
just waiting for the site to become available.

As the `@todo`'s say, this needs some work, as I'm unsure
how to use secrets and get around `set -e` as part of
the deployment.
**I'm looking for input for this :)**

Ontop of that, also setting up `concurrency` rules to
`ci-tests`, so if a second push is made, we cancel the
old and unrelated workflow.
@dpl-platform-bot dpl-platform-bot had a problem deploying to optimize-gh-actions October 2, 2024 09:53 Failure
@rasben rasben closed this Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants