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

fix: make GITHUB_REF env var optional #82

Merged

Conversation

billputer
Copy link
Contributor

Fixes #80

Certain workflows don't set a GITHUB_REF variable, because the triggering event doesn't have a branch or tag, so this PR makes GITHUB_REF optional. This changes the ordering of tags in tests since the Branch tag is now added at the end. It also adds two tests to validate this behavior, although I'm not convinced they provide much value.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@piradeepk piradeepk self-assigned this Jun 30, 2020
* master:
  chore: Update dist
  fix: Make tagging optional (#92)
  chore: Bump eslint from 7.3.1 to 7.4.0 (#94)
  chore: Update dist
  chore: Bump aws-sdk from 2.707.0 to 2.708.0 (#90)
  chore: update dependabot schedule (#89)
  chore(release): 1.4.2
  chore: Update dist
  chore: Bump aws-sdk from 2.706.0 to 2.707.0 (#88)
  chore: Switch to GitHub-native Dependabot
  chore: Update dist
  chore: Bump aws-sdk from 2.704.0 to 2.706.0
  chore: Update dist
  fix: add comma to set of special characters (#78)
  chore: Bump jest from 26.0.1 to 26.1.0
  chore: Update dist
  chore: Bump aws-sdk from 2.692.0 to 2.704.0
  chore: Bump eslint from 7.2.0 to 7.3.1
@billputer
Copy link
Contributor Author

I've updated this to fix conflicts introduced in #92.

Interestingly enough, although #92 allows skipping setting session tags, the code still requires that the associated environment variables are set. It might be worth splitting that functionality out into a separate function.

@allisaurus allisaurus assigned allisaurus and unassigned piradeepk Jul 27, 2020
Copy link
Contributor

@allisaurus allisaurus left a comment

Choose a reason for hiding this comment

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

Thanks a lot @billputer ! Code LGTM. Can you provide some test output or guidance on which workflows may trigger the original issue? I tried to reproduce by setting a status but no dice.

@billputer
Copy link
Contributor Author

Thanks a lot @billputer ! Code LGTM. Can you provide some test output or guidance on which workflows may trigger the original issue? I tried to reproduce by setting a status but no dice.

I'm specifically using the "deployment" webhook event. An external system creates a Deployment in GitHub which triggers our workflow. Here's a truncated version:

name: deploy
on: ['deployment']

jobs:
  deploy:
    runs-on: ubuntu-18.04
    steps:
    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-west-2
    # ...rest of deploy code

If you're interested in triggering that, here's roughly how we've been creating a GitHub Deployment in testing.

npm install @octokit/rest
export GITHUB_TOKEN=<github_token_here>
node
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({
  auth: process.env.GITHUB_TOKEN,
  userAgent: 'deploy testing',
})

octokit.repos.createDeployment({
  owner: "billputer",
  repo: "deploy-testing",
  ref: "4cd8eff6e93378175f2d204ef5235cf2271d59d3",
  description: "Deploy triggered by Bill via CLI",
  environment: "testing",
  task: "deploy",
  payload: {},
  required_contexts: [],
  auto_merge: false,
}).then(data => { console.log(data) });

The key here is that the "ref" is a commit sha. If you instead pass a ref of "master", the GITHUB_REF environment variable is set.

Let me know if that's helpful, or if you need any additional context.

@mergify mergify bot merged commit ba5041f into aws-actions:master Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Action fails when GITHUB_REF does not exist
3 participants