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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
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.

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 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/deployments@v1.5.0
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.

- 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/branchlint-action@2.1.0
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.

Comment on lines +107 to +112
# @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
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.

3 participants